UNPKG

@stratusjs/idx

Version:

AngularJS idx/property Service and Components bundle to be used as an add on to StratusJS

129 lines (127 loc) 7.25 kB
System.register(["lodash", "@stratusjs/runtime/stratus", "@stratusjs/angularjs/services/model", "@stratusjs/core/misc", "@stratusjs/core/environment"], function (exports_1, context_1) { "use strict"; var lodash_1, stratus_1, model_1, misc_1, environment_1, min, packageName, moduleName, componentName, localDir; var __moduleName = context_1 && context_1.id; return { setters: [ function (lodash_1_1) { lodash_1 = lodash_1_1; }, function (stratus_1_1) { stratus_1 = stratus_1_1; }, function (model_1_1) { model_1 = model_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 = 'property'; componentName = 'details-sub-section'; localDir = `${stratus_1.Stratus.BaseUrl}${stratus_1.Stratus.DeploymentPath}@stratusjs/${packageName}/src/${moduleName}/`; stratus_1.Stratus.Components.IdxPropertyDetailsSubSection = { bindings: { ngModel: '=', items: '@', sectionName: '@', className: '@', template: '@', }, controller($attrs, $scope) { $scope.uid = misc_1.safeUniqueId(packageName, moduleName, componentName); $scope.elementId = $attrs.elementId || $scope.uid; $scope.className = $attrs.className || 'sub-detail-section'; $scope.sectionName = $attrs.sectionName || ''; $scope.sectionNameId = lodash_1.camelCase($scope.sectionName) + '_' + $scope.elementId; const defaultItems = {}; $scope.items = $attrs.items && misc_1.isJSON($attrs.items) ? JSON.parse($attrs.items) : defaultItems; $scope.visibleFields = false; $scope.model = null; const checkForVisibleFields = () => { Object.keys($scope.items).forEach((item) => { if (Object.prototype.hasOwnProperty.call($scope.model.data, item) && $scope.model.data[item] !== 0 && $scope.model.data[item] !== '' && $scope.model.data[item] !== '0' && !lodash_1.isString($scope.items[item])) { if (!($scope.model.data[item] === false && lodash_1.get($scope.items[item], 'false') === '')) { if (Object.prototype.hasOwnProperty.call($scope.items[item], 'appendField') && Object.prototype.hasOwnProperty.call($scope.model.data, $scope.items[item].appendField) && $scope.model.data[$scope.items[item].appendField] !== '') { $scope.items[item].append = ' ' + $scope.model.data[$scope.items[item].appendField]; } else if (Object.prototype.hasOwnProperty.call($scope.items[item], 'appendFieldBackup') && Object.prototype.hasOwnProperty.call($scope.model.data, $scope.items[item].appendFieldBackup) && $scope.model.data[$scope.items[item].appendFieldBackup] !== '') { $scope.items[item].append = ' ' + $scope.model.data[$scope.items[item].appendFieldBackup]; } if (lodash_1.get($scope.items[item], 'hideEmpty') !== false && (lodash_1.isArray($scope.model.data[item]) && $scope.model.data[item].length <= 0)) { $scope.items[item].hide = true; } else { $scope.visibleFields = true; } } else if ($scope.model.data[item] === false && lodash_1.get($scope.items[item], 'hideEmpty') !== false) { $scope.items[item].hide = true; } } }); }; if ($scope.sectionName.startsWith('{')) { const stopWatchingSectionName = $scope.$watch('$ctrl.sectionName', (data) => { $scope.sectionName = data; $scope.sectionNameId = lodash_1.camelCase($scope.sectionName) + '_' + $scope.elementId; stopWatchingSectionName(); }); } if (Object.keys($scope.items).length === 0) { const stopWatchingItems = $scope.$watch('$ctrl.items', (data) => { if (Object.keys($scope.items).length === 0) { const blankItems = {}; $scope.items = data && misc_1.isJSON(data) ? JSON.parse(data) : blankItems; $scope.convertItemsToObject(); } stopWatchingItems(); }); } const stopWatchingModel = $scope.$watch('$ctrl.ngModel', (data) => { if (data instanceof model_1.Model && data !== $scope.model) { $scope.model = data; checkForVisibleFields(); stopWatchingModel(); } }); this.$onInit = () => { $scope.convertItemsToObject(); }; $scope.convertItemsToObject = () => { lodash_1.forEach($scope.items, (itemValue, itemKey) => { if (typeof itemValue === 'string') { $scope.items[itemKey] = { name: itemValue }; } }); }; $scope.typeOf = (item) => lodash_1.isArray(item) ? 'array' : typeof item; $scope.isArray = (item) => lodash_1.isArray(item); }, templateUrl: ($attrs) => `${localDir}${$attrs.template || componentName}.component${min}.html` }; } }; }); //# sourceMappingURL=details-sub-section.component.js.map