UNPKG

@stratusjs/idx

Version:

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

1 lines 5.03 kB
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,localDir,localDistStyle;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","idx","office","search",localDir=`${stratus_1.Stratus.BaseUrl}${stratus_1.Stratus.DeploymentPath}@stratusjs/idx/src/office/`,localDistStyle=`${stratus_1.Stratus.BaseUrl}${stratus_1.Stratus.DeploymentPath}@stratusjs/idx/dist/idx.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("idx","office","search"),$scope.elementId=$attrs.elementId||$scope.uid,stratus_1.Stratus.Instances[$scope.elementId]=$scope,$scope.selectionGroup={name:"",group:[]},$scope.itemsSelectable=[],$attrs.tokenUrl&&Idx.setTokenURL($attrs.tokenUrl),stratus_1.Stratus.Internals.CssLoader(localDistStyle).then(),this.$onInit=()=>{$scope.listId=$attrs.listId||null,$scope.listInitialized=!1,$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(!0),$scope.options=$attrs.options&&misc_1.isJSON($attrs.options)?JSON.parse($attrs.options):{},$scope.options.query??={},$scope.options.query.where??={},$scope.options.tokenUrl&&Idx.setTokenURL($scope.options.tokenUrl),Idx.registerSearchInstance($scope.elementId,"office",$scope,$scope.listId),$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=!0,Idx.emit("init",$scope)})},$scope.search=async()=>{let listScope;$scope.listId&&(listScope=Idx.getListInstance($scope.listId,"office")),listScope&&await listScope.search($scope.options.query,!0)},$scope.collectionUpdated=async(_listScope,collection)=>{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);!remove&&-1===selectedIndex?($scope.selectionGroup.group.push(itemId),$scope.itemsSelectable.forEach(officeSelectable=>{officeSelectable.id===itemId&&(officeSelectable.selected=!0)})):(selectedIndex>-1&&$scope.selectionGroup.group.splice(selectedIndex,1),$scope.itemsSelectable.forEach(officeSelectable=>{officeSelectable.id===itemId&&(officeSelectable.selected=!1)})),$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;lodash_1.isArray(parentVariable)?(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):updatedValue=$scope.selectionGroup,Idx.updateScopeValuePath(stratus_1.Stratus.Instances[$scope.syncInstance],$scope.syncInstanceVariable,updatedValue).then()}},$scope.refreshSearchWidgetOptions=async listScope=>{!listScope&&$scope.listId&&(listScope=Idx.getListInstance($scope.listId)),listScope&&($scope.listInitialized=!0)},$scope.on=(emitterName,callback)=>Idx.on($scope.elementId,emitterName,callback),$scope.remove=()=>{}},templateUrl:$attrs=>`${localDir}${$attrs.template||"search"}.component${min}.html`}}}});