@stratusjs/idx
Version:
AngularJS idx/property Service and Components bundle to be used as an add on to StratusJS
172 lines (170 loc) • 9.54 kB
JavaScript
System.register(["./search.group-selector.component.less", "lodash", "@stratusjs/runtime/stratus", "@stratusjs/core/misc", "@stratusjs/core/environment"], function (exports_1, context_1) {
"use strict";
var lodash_1, stratus_1, misc_1, environment_1, min, packageName, moduleName, componentName, localDir, localDistStyle;
var __moduleName = context_1 && context_1.id;
return {
setters: [
function (_1) {
},
function (lodash_1_1) {
lodash_1 = lodash_1_1;
},
function (stratus_1_1) {
stratus_1 = stratus_1_1;
},
function (misc_1_1) {
misc_1 = misc_1_1;
},
function (environment_1_1) {
environment_1 = environment_1_1;
}
],
execute: function () {
min = !environment_1.cookie('env') ? '.min' : '';
packageName = 'idx';
moduleName = 'office';
componentName = 'search';
localDir = `${stratus_1.Stratus.BaseUrl}${stratus_1.Stratus.DeploymentPath}@stratusjs/${packageName}/src/${moduleName}/`;
localDistStyle = `${stratus_1.Stratus.BaseUrl}${stratus_1.Stratus.DeploymentPath}@stratusjs/${packageName}/dist/${packageName}.bundle.min.css`;
stratus_1.Stratus.Components.IdxOfficeSearch = {
bindings: {
elementId: '@',
tokenUrl: '@',
listId: '@',
listLinkUrl: '@',
listLinkTarget: '@',
options: '@',
template: '@',
variableSync: '@',
syncInstance: '@',
syncInstanceVariable: '@',
syncInstanceVariableIndex: '@'
},
controller($attrs, $scope, Idx) {
$scope.uid = misc_1.safeUniqueId(packageName, moduleName, componentName);
$scope.elementId = $attrs.elementId || $scope.uid;
stratus_1.Stratus.Instances[$scope.elementId] = $scope;
$scope.selectionGroup = {
name: '',
group: []
};
$scope.itemsSelectable = [];
if ($attrs.tokenUrl) {
Idx.setTokenURL($attrs.tokenUrl);
}
stratus_1.Stratus.Internals.CssLoader(localDistStyle).then();
this.$onInit = () => {
$scope.listId = $attrs.listId || null;
$scope.listInitialized = false;
$scope.listLinkUrl = $attrs.listLinkUrl || '/property/office/list';
$scope.listLinkTarget = $attrs.listLinkTarget || '_self';
$scope.syncInstance = $attrs.syncInstance || null;
$scope.syncInstanceVariable = $attrs.syncInstanceVariable || null;
$scope.syncInstanceVariableIndex = ($attrs.syncInstanceVariableIndex && lodash_1.isString($attrs.syncInstanceVariableIndex) ?
parseInt($attrs.syncInstanceVariableIndex, 10) : null) || ($attrs.syncInstanceVariableIndex && lodash_1.isNumber($attrs.syncInstanceVariableIndex) ?
$attrs.syncInstanceVariableIndex : null) || 0;
$scope.updateSyncedGroupSelection(true);
$scope.options = $attrs.options && misc_1.isJSON($attrs.options) ? JSON.parse($attrs.options) : {};
$scope.options.query ??= {};
$scope.options.query.where ??= {};
if ($scope.options.tokenUrl) {
Idx.setTokenURL($scope.options.tokenUrl);
}
Idx.registerSearchInstance($scope.elementId, moduleName, $scope, $scope.listId);
if ($scope.listId) {
Idx.on($scope.listId, 'init', $scope.refreshSearchWidgetOptions);
Idx.on($scope.listId, 'searching', $scope.refreshSearchWidgetOptions);
Idx.on($scope.listId, 'collectionUpdated', $scope.collectionUpdated);
}
$scope.$applyAsync(() => {
$scope.initialized = true;
Idx.emit('init', $scope);
});
};
$scope.search = async () => {
let listScope;
if ($scope.listId) {
listScope = Idx.getListInstance($scope.listId, 'office');
}
if (listScope) {
await listScope.search($scope.options.query, true);
}
};
$scope.collectionUpdated = async (_listScope, collection) => {
if (lodash_1.isEmpty(lodash_1.trim($scope.selectionGroup.name)) &&
!lodash_1.isEmpty(lodash_1.trim($scope.options.query.where.OfficeName))) {
$scope.selectionGroup.name = $scope.options.query.where.OfficeName;
}
$scope.itemsSelectable = [];
collection.models.forEach((office) => {
$scope.itemsSelectable.push({
id: office._OfficeNumber,
listing: office,
selected: $scope.selectionGroup.group.includes(office._OfficeNumber)
});
});
};
$scope.toggleSelected = (itemId, remove) => {
const selectedIndex = $scope.selectionGroup.group.indexOf(itemId);
const nowSelected = remove ? false : (selectedIndex === -1);
if (nowSelected) {
$scope.selectionGroup.group.push(itemId);
$scope.itemsSelectable.forEach((officeSelectable) => {
if (officeSelectable.id === itemId) {
officeSelectable.selected = true;
}
});
}
else {
if (selectedIndex > -1) {
$scope.selectionGroup.group.splice(selectedIndex, 1);
}
$scope.itemsSelectable.forEach((officeSelectable) => {
if (officeSelectable.id === itemId) {
officeSelectable.selected = false;
}
});
}
$scope.updateSyncedGroupSelection();
};
$scope.updateSyncedGroupSelection = (initialize) => {
if ($scope.syncInstance &&
stratus_1.Stratus.Instances[$scope.syncInstance] &&
$scope.syncInstanceVariable) {
const parentVariable = Idx.getScopeValuePath(stratus_1.Stratus.Instances[$scope.syncInstance], $scope.syncInstanceVariable);
let updatedValue;
if (lodash_1.isArray(parentVariable)) {
if (initialize &&
!lodash_1.isEmpty(parentVariable[$scope.syncInstanceVariableIndex]) &&
!lodash_1.isString(parentVariable[$scope.syncInstanceVariableIndex]) &&
Object.prototype.hasOwnProperty.call(parentVariable[$scope.syncInstanceVariableIndex], 'name')) {
$scope.selectionGroup = parentVariable[$scope.syncInstanceVariableIndex];
}
updatedValue = parentVariable;
updatedValue[$scope.syncInstanceVariableIndex] = $scope.selectionGroup;
}
else {
updatedValue = $scope.selectionGroup;
}
Idx.updateScopeValuePath(stratus_1.Stratus.Instances[$scope.syncInstance], $scope.syncInstanceVariable, updatedValue).then();
}
};
$scope.refreshSearchWidgetOptions = async (listScope) => {
if (!listScope &&
$scope.listId) {
listScope = Idx.getListInstance($scope.listId);
}
if (listScope) {
$scope.listInitialized = true;
}
};
$scope.on = (emitterName, callback) => Idx.on($scope.elementId, emitterName, callback);
$scope.remove = () => {
};
},
templateUrl: ($attrs) => `${localDir}${$attrs.template || componentName}.component${min}.html`
};
}
};
});
//# sourceMappingURL=search.component.js.map