4 app.directive('afterRender', [ function() {
9 link : function(scope, element, attrs) {
10 if (attrs) { scope.$eval(attrs.afterRender) }
11 scope.$emit('onAfterRender')
17 app.directive("search", function() {
19 // replace custom element with html5 markup
21 //+ '<c:set var="zeroidx" value="0" />'
22 + '<div ng-repeat="a in optionsSizeArray track by $index"> '
23 + '<div id="{{sId}}{{a}}" > '
24 + ' <div class="form-field form-field__glued pull-left size-onefourth" style=" width:25%;" >'
25 + ' <div att-search="options" ng-model="valueOptions[a]" placeholder="Select"></div> '
27 + ' <div class="form-field form-field__glued pull-left size-onefourth" style=" width:25%;"> '
28 + ' <div att-search="operators" ng-model="compareOptions[a]" placeholder="Select"></div> '
30 + ' <div class="form-field form-field__glued pull-left size-onefourth" style=" width:25%;">'
31 + ' <input ng-model="searchValue[a]" type="text" placeholder="What are you looking for?" style=" border-radius:0px 5px 5px 0px" > '
33 + ' <div class="form-field form-field__glued pull-left size-onefourth" style=" width:25%; padding-left:5px;"> '
34 + ' <button ng-click="remove(sId,a)" class="myzkBtn" >-</button>'
35 + ' <button ng-if="$index==0" ng-click="addSearch(sId,a,optionsSizeArray)" class="myzkBtn" >+</button> '
36 + ' <button ng-if="$index==0" ng-click="updateparent({filter: { valueOptions: valueOptions, compareOptions: compareOptions, searchValue : searchValue } })" class="myzkBtn" style="background-image:url(static/ebz/images/searchIcon.png); background-repeat: no-repeat; background-position: center;"> </button>'
42 // restrict usage to element only since we use attributes for APIs
50 ,jsonForOperator : '='
53 link: function(scope, iElement, iAttrs){
54 scope.optionsSizeArray = [];
56 //scope.options = JSON.parse(JSON.stringify(iAttrs.jsonForOption));
57 //scope.operators = JSON.parse(iAttrs.operators);
59 scope.$watch("jsonForOption", function(newval, oldval) {
60 scope.options = JSON.parse(JSON.stringify(oldval));
62 scope.evalRepeatIndex(scope.options.length);
67 scope.evalRepeatIndex = function(size){
68 for(index = 0; index < size; index++) {
69 scope.optionsSizeArray.push(index);
73 scope.$watch("jsonForOperator", function(newval, oldval) {
74 scope.operators = JSON.parse(JSON.stringify(oldval));
78 if(getParameterByName("search")!=null && getParameterByName("search")!=''){
79 if((getParameterByName("location")!=null && getParameterByName("location")!='')){
80 scope.searchValue[0]=JSON.parse(JSON.stringify(getParameterByName("location")));
81 scope.valueOptions[0]={index:0,value:'Location Name',title:"Location Name",alias:'Location Name'};
82 scope.compareOptions[0]={index:1,value:'Contains',title:"Contains",alias:'Contains'};
83 }else if((getParameterByName("userLastName")!=null && getParameterByName("userLastName")!='')){
84 scope.searchValue[0]=JSON.parse(JSON.stringify(getParameterByName("userLastName")));
85 scope.valueOptions[0]= {index: 0, value: 'Last Name', title: 'Last Name', alias:'Last Name'};
86 scope.compareOptions[0]={index:1,value:'Contains',title:"Contains",alias:'Contains'};
89 scope.$watch("searchId", function(newval, oldval) {
94 scope.showHide = function(div){
96 $("#s1").css('display', 'none');
102 scope.hideDiv = function(){
104 console.log(scope.optionsSizeArray);
107 for (i = 1; i < scope.optionsSizeArray.length; i++) {
108 var element = "#"+scope.sId+i;
109 $(element).css('display', 'none');
123 controller: function ($scope) {
125 $scope.addSearch = function(searchId, index, optionsLength){
128 for(var i = 0; i<=optionsLength.length ;i++){
129 var element = "#"+searchId+i;
130 if($(element).css('display') == 'none'){
131 $(element).css('display', 'inline');
139 $scope.remove = function(searchId, index){
140 var remove = "#"+searchId+index;
142 $(remove).css("display", "none");
149 $scope.valueOptions[index]=v;
150 $scope.compareOptions[index]=v;
151 $scope.searchValue[index]="";
154 $scope.search = function() {
156 valueOptions : $scope.valueOptions,
157 compareOptions : $scope.compareOptions,
158 searchValue : $scope.searchValue
163 valueOptions : $scope.valueOptions,
164 compareOptions : $scope.compareOptions,
165 searchValue : $scope.searchValue
168 $scope.mSearch = data;
169 $scope.valueOptions=[];
170 $scope.compareOptions=[];
171 $scope.searchValue=[];
177 app.directive('phoneNumberMask', [function(){
184 link: function(scope, el, attrs){
185 scope.$watch(attrs.phoneNumberMask, function(newValue, oldValue) {
188 scope.ngModel= scope.ngModel.replace(/(\+1)?(\d{3})(\d{3})(\d{4})/, '$2.$3.$4');
189 $(el).mask("999.999.9999");
191 scope.$watch("ngModel", function() {
192 var current = $(el).val();
193 if(scope.ngModel && /^(\+1)?\d{3,}$/.test(scope.ngModel))
194 scope.ngModel= scope.ngModel.replace(/(\+1)?(\d{3})(\d{3})(\d{4})/, '$2.$3.$4');
201 app.directive('allowOnlyNumber', [function(){
204 link: function(scope, element, attrs, modelCtrl) {
205 modelCtrl.$parsers.push(function (inputValue) {
206 if (inputValue == undefined) return '';
207 var transformedInput = inputValue.replace(/[^0-9]/g, '');
208 if (transformedInput!=inputValue) {
209 modelCtrl.$setViewValue(transformedInput);
213 return transformedInput;
219 app.directive('showProcessing', function(){
222 link: function(scope, elem, attrs) {
223 elem.bind('click', function() {
224 $(".overlayed").css("display","inline");
225 $(".loadingId").css("display","inline");
231 app.directive("searchCriteria", function() {
233 // replace custom element with html5 markup
235 + '<div ng-repeat="a in searchCriterion track by $index" ng-show="isShown[$index]"> '
236 + ' <div class="form-field form-field__glued form-field__square size-onefourth left_round_border">'
237 + ' <div att-search="availableOptions[$index]" ng-model="valueOptions[$index]"></div> '
239 + ' <div class="form-field form-field__glued form-field__square size-onefourth"> '
240 + ' <div att-search="availableOperators[$index]" ng-model="compareOptions[$index]" > </div> '
242 + ' <div class="form-field form-field__glued form-field__square size-onefourth right_round_border">'
243 + ' <input ng-show="!availableValues[$index] || availableValues[$index].length===0" ng-model="searchValue[$index]" type="text" placeholder="What are you looking for?" class="fn-ebz-text" style="width:100%;" > '
244 + ' <div ng-show="availableValues[$index] && availableValues[$index].length!==0" att-search="availableValues[$index]" ng-model="searchValue[$index]"></div> '
246 + ' <div class="form-field form-field__glued form-field__square size-onefourth" style=" padding-left:5px;" > '
247 + ' <button ng-show="$index!=0" ng-click="removeSearchCriteria($index)" class="myzkBtn">-</button>'
248 + ' <button ng-show="$index==0" ng-click="addSearchCriteria($index)" class="myzkBtn">+</button> '
249 + ' <button ng-show="$index==0" ng-click="search()" class="myzkBtn" style="background-image:url(static/ebz/images/searchIcon.png); background-repeat: no-repeat; background-position: center;"> </button>'
254 // restrict usage to element only since we use attributes for APIs
259 mSearch : '=ngModel',
261 ,options : '=jsonForOption'
262 ,operators : '=jsonForOperator'
265 controller: function ($scope) {
266 $scope.isShown = [true];
267 $scope.searchCriterion = [];
268 $scope.valueOptions=[];
269 $scope.compareOptions=[];
270 $scope.searchValue=[];
271 $scope.availableOperators=[];
272 $scope.availableValues=[];
273 $scope.availableOptions = [];
275 $scope.insertEmptyOption = function(arr){
276 var hasEmpty = false;
277 $.each(arr, function(i, a){
283 $.each(arr, function(i, a){
286 arr.unshift({index: 0, value: '', title: 'Select', alias:'Select'});
289 $scope.findFirstOption = function(arr){
292 $scope.insertEmptyOption($scope.options);
293 $scope.insertEmptyOption($scope.operators);
295 for(var i = 0, l= $scope.options.length; i<l; i++) {
296 var option= $scope.options[i];
297 var n = option.maxOccurs;
298 if(option.value!==''){
299 if(n && Number(n)===n && n%1===0){ //maxOccurs is specified
300 for(var j=0; j<n; j++){
301 $scope.searchCriterion.push("");
302 $scope.availableOperators.push($scope.operators);
304 $scope.availableValues.push(valueArr);
305 $scope.availableOptions.push($scope.options);
306 $scope.isShown.push(false);
309 $scope.searchCriterion.push("");
310 $scope.availableOperators.push($scope.operators);
312 $scope.availableValues.push(valueArr);
313 $scope.availableOptions.push($scope.options);
314 $scope.isShown.push(false);
318 $scope.isShown.pop();
320 $scope.updateAvailableOptions = function(index, isFirst){
321 var selectedOptions = [];//{value:'name', occurs: }
322 if($scope.options && $scope.options.length > 0){
323 $.each($scope.valueOptions, function(i, a){
327 var s= $.grep(selectedOptions, function(e){ return e.value === v });
332 selectedOptions.push({value: v, occurs:1});
335 var o= $.grep($scope.options, function(e){ return e.value === v });
337 if("operators" in o[0]){
338 $scope.availableOperators[i]=o[0].operators;
339 $scope.insertEmptyOption($scope.availableOperators[i]);
341 $scope.availableOperators[i]=$scope.operators;
343 if("values" in o[0]){
344 $scope.availableValues[i]=o[0].values;
346 $scope.availableValues[i]=[];
351 for(var j = 0 , l = $scope.availableOptions.length; j<l ; j++){
354 $.each($scope.options, function(i, a){
355 var s= $.grep(selectedOptions, function(e){ return e.value === a.value });
356 var maxOccurs = "maxOccurs" in a ? a.maxOccurs :1;
357 if(s.length > 0 && s[0].occurs >= maxOccurs && ($scope.valueOptions[j] && $scope.valueOptions[j].value !== s[0].value)){// reach limit
359 newOptions.push({index: aoi, value: a.value, title: a.title, alias:a.alias});
363 $scope.availableOptions[j] = newOptions;
365 if($scope.availableValues[j].length>0)
366 $scope.searchValue[j]= $scope.availableValues[j][0];
368 $scope.searchValue[j]="";
370 $scope.compareOptions[j]= $scope.availableOperators[j][0];
375 if(typeof index !== 'undefined' && !isFirst){
376 if($scope.availableValues[index].length>0)
377 $scope.searchValue[index]= $scope.availableValues[index][0];
379 $scope.searchValue[index]="";
383 $scope.updateAvailableOptions(undefined, true);
384 $.each($scope.availableOptions, function(j, a){
385 $scope.valueOptions[j]= a[0];
387 $scope.addSearchCriteria = function(index){
388 for(var i = 0 , l =$scope.isShown.length; i<l; i++ ){
389 if(!$scope.isShown[i]){
390 $scope.isShown[i]= true;
397 $scope.removeSearchCriteria = function(index){
398 $scope.isShown[index]= false;
401 $scope.valueOptions[index]=$scope.availableOptions[index][0];
402 $scope.compareOptions[index]=$scope.availableOperators[index][0];
403 $scope.searchValue[index]="";
405 $scope.search = function() {
406 //remove empty criteria
410 for(var i = 0 , l=$scope.valueOptions.length; i<l ; i++){
411 if($scope.valueOptions[i].value==='' || $scope.compareOptions[i].value==='' ||(typeof $scope.searchValue[i] ==='string' && $scope.searchValue[i] ==='') || $scope.searchValue[i].value === ''){
413 vo.push($scope.valueOptions[i]);
414 co.push($scope.compareOptions[i]);
415 sv.push($scope.searchValue[i]);
418 $scope.updateparent({filter: { valueOptions: vo, compareOptions: co, searchValue :sv } });
421 $scope.$watchCollection("valueOptions", function(collection, oldValue ){
424 for(var i = 0 , l =collection.length; i<l; i++ ){
425 if(!oldValue[i] || oldValue[i].value!=collection[i].value){
431 $scope.updateAvailableOptions(index);
440 app.directive("selectUser", function() {
442 // replace custom element with html5 markup
444 + '<table style="width:660px; margin-left:-12px;" >'
447 + ' <th style="width:325px;">{{availableTitle}}</th> '
448 + ' <th style="width:10px;"></th> '
449 + ' <th style="width:325px;">{{userTitle}}</th> '
454 + ' <td style="width:325px;">'
455 + ' <div class="ebz-listbox">'
456 + ' <label ng-repeat="canditateId in canditateIds track by canditateId.ociUserId" style="display:block;"> '
457 + ' <input type="checkbox" style="margin-top: 10px;" ng-model="canditateId.available" att-checkbox ng-change="checkCanditate($index)"/> {{canditateId.firstName}} {{canditateId.lastName}}({{canditateId.phone}})<br/>'
461 + '<td valign="middle" width="10px">'
462 + ' <img src="static/images/rightarrow_g.png" id="removeBtn" ng-click="chooseSelected()" ng-hide="oneMax && chosenIds.length==1"/>'
463 + ' <img src="static/images/leftarrow_g.png" id="chooseBtn" ng-click="removeSelected()" ng-show="oneMax && chosenIds.length==1"/>'
465 + ' <img src="static/images/leftarrow_g.png" id="chooseBtn" ng-click="removeSelected()" ng-hide="oneMax"/>'
467 + ' <img id="chooseAllBtn" src="static/images/rightrightarrow_g.png" ng-click="chooseAll()" ng-hide="oneMax"/>'
469 + ' <img style="cursor:pointer" id="removeAllBtn" src="static/images/leftleftarrow_g.png" ng-click="removeAll()" ng-hide="oneMax"/>'
471 + '<td style="width:325px;">'
472 + ' <div class="ebz-listbox" >'
473 + ' <label ng-repeat="chosenId in chosenIds" style="display:block;">'
474 + ' <input type="checkbox" style=" margin-top :10px;" att-checkbox ng-model="chosenId.available"/> {{chosenId.firstName}} {{chosenId.lastName}}({{chosenId.phone}})<br/>'
483 // restrict usage to element only since we use attributes for APIs
487 chosenIds : '=assignedUsers'
488 ,availableUsers : '='
490 ,availableTitle : '='
493 link: function(scope, iElement, attrs){
495 scope.$watch("userTitle", function(newval, oldval) {
496 scope.userTitle = newval;
498 scope.$watch("availableTitle", function(newval, oldval) {
499 scope.availableTitle = newval;
502 scope.$watch("availableUsers", function(newval, oldval) {
503 scope.availableUsers = newval;
504 scope.canditateIds= scope.getArrayRemoved(scope.availableUsers, scope.chosenIds);
509 controller: function ($scope) {
510 $scope.getArrayRemoved = function(from, removed){
511 var retArray = (from)? from:[];
512 if(retArray && retArray.length >0 && removed){
513 for(var i = 0, l = removed.length; i<l; i++ ){
514 retArray = $.grep(retArray, function(e){ return e.ociUserId !== removed[i].ociUserId; });
519 $scope.canditateIds= $scope.getArrayRemoved($scope.availableUsers, $scope.chosenIds);
520 $scope.chooseAll = function() {
522 var dataFromTableData = $scope.canditateIds;
523 for (var i = dataFromTableData.length - 1; i >= 0; i--){
524 if(!$scope.chosenIds)
526 $scope.chosenIds.push(dataFromTableData[i]);
527 $scope.canditateIds.splice(i,1);
530 var dataFromChoosonTable = $scope.chosenIds;
531 for (var i = dataFromChoosonTable.length - 1; i >= 0; i--){
532 if(dataFromChoosonTable[i].available){
533 $scope.chosenIds[i].available=false;
538 $scope.removeAll = function() {
539 var dataFromTableData = $scope.chosenIds;
540 for (var i = dataFromTableData.length - 1; i >= 0; i--){
541 $scope.canditateIds.push(dataFromTableData[i]);
542 $scope.chosenIds.splice(i,1);
545 var dataFromChoosonTable = $scope.canditateIds;
546 for (var i = dataFromChoosonTable.length - 1; i >= 0; i--){
547 if(dataFromChoosonTable[i].available){
548 $scope.canditateIds[i].available=false;
553 $scope.chooseSelected = function() {
555 var dataFromTableData = $scope.canditateIds;
557 for (var i = dataFromTableData.length - 1; i >= 0; i--){
559 if(dataFromTableData[i].available){
560 if(!$scope.chosenIds)
562 $scope.chosenIds.push(dataFromTableData[i]);
563 $scope.canditateIds.splice(i,1);
567 var dataFromChoosonTable = $scope.chosenIds;
568 for (var i = dataFromChoosonTable.length - 1; i >= 0; i--){
569 if(dataFromChoosonTable[i].available){
570 $scope.chosenIds[i].available=false;
574 $scope.removeSelected = function() {
576 var dataFromTableData = $scope.chosenIds;
578 for (var i = dataFromTableData.length - 1; i >= 0; i--){
579 if(dataFromTableData[i].available){
580 $scope.canditateIds.push(dataFromTableData[i]);
581 $scope.chosenIds.splice(i,1);
585 var dataFromChoosonTable = $scope.canditateIds;
586 for (var i = dataFromChoosonTable.length - 1; i >= 0; i--){
587 if(dataFromChoosonTable[i].available){
588 $scope.canditateIds[i].available=false;
592 $scope.checkCanditate = function(index) {
594 for (var i = $scope.canditateIds.length - 1; i >= 0; i--){
596 $scope.canditateIds[i].available=false;
605 app.directive("selectString", function() {
607 // replace custom element with html5 markup
609 + '<table style="width:660px;">'
612 + ' <th style="width:325px;">{{availableTitle}}</th> '
613 + ' <th style="width:10px;"></th> '
614 + ' <th style="width:325px;">{{assignedTitle}}</th> '
619 + ' <td style="width:325px;">'
620 + ' <div class="ebz-listbox">'
621 + ' <label ng-repeat="canditateId in canditateIds track by $index" style="display:block;"> '
622 + ' <input type="checkbox" style="margin-top: 10px;" ng-model="canditateId.available" att-checkbox /> {{canditateId}}<br/>'
626 + '<td valign="middle" width="10px">'
627 + ' <img src="static/images/rightarrow_g.png" id="removeBtn" ng-click="chooseSelected()" />'
629 + ' <img src="static/images/leftarrow_g.png" id="chooseBtn" ng-click="removeSelected()" />'
631 + ' <img id="chooseAllBtn" src="static/images/rightrightarrow_g.png" ng-click="chooseAll()" />'
633 + ' <img style="cursor:pointer" id="removeAllBtn" src="static/images/leftleftarrow_g.png" ng-click="removeAll()" />'
635 + '<td style="width:325px;">'
636 + ' <div class="ebz-listbox" >'
637 + ' <label ng-repeat="chosenId in chosenIds" style="display:block;">'
638 + ' <input type="checkbox" style=" margin-top :10px;" att-checkbox ng-model="chosenId.available"/> {{chosenId}}<br/>'
647 // restrict usage to element only since we use attributes for APIs
651 chosenIds : '=assignedOptions'
652 ,availableOptions : '='
653 ,availableTitle : '@'
656 link: function(scope, iElement, attrs){
657 scope.$watch("availableOptions", function(newval, oldval) {
658 scope.availableOptions = newval;
659 scope.canditateIds= scope.getArrayRemoved(scope.availableOptions, scope.chosenIds);
664 controller: function ($scope) {
665 $scope.getArrayRemoved = function(from, removed){
666 var retArray = (from)? from:[];
667 if(retArray && retArray.length >0 && removed){
668 for(var i = 0, l = removed.length; i<l; i++ ){
669 retArray = $.grep(retArray, function(e){ return e !== removed[i]; });
675 $scope.canditateIds= $scope.getArrayRemoved($scope.availableOptions, $scope.chosenIds);
676 $scope.chooseAll = function() {
678 var dataFromTableData = $scope.canditateIds;
679 for (var i = dataFromTableData.length - 1; i >= 0; i--){
680 if(!$scope.chosenIds)
682 $scope.chosenIds.push(dataFromTableData[i]);
683 $scope.canditateIds.splice(i,1);
688 $scope.removeAll = function() {
689 var dataFromTableData = $scope.chosenIds;
690 for (var i = dataFromTableData.length - 1; i >= 0; i--){
691 $scope.canditateIds.push(dataFromTableData[i]);
692 $scope.chosenIds.splice(i,1);
697 $scope.chooseSelected = function() {
699 var dataFromTableData = $scope.canditateIds;
701 for (var i = dataFromTableData.length - 1; i >= 0; i--){
703 if(dataFromTableData[i].available){
704 if(!$scope.chosenIds)
706 $scope.chosenIds.push(dataFromTableData[i]);
707 $scope.canditateIds.splice(i,1);
712 $scope.removeSelected = function() {
714 var dataFromTableData = $scope.chosenIds;
716 for (var i = dataFromTableData.length - 1; i >= 0; i--){
717 if(dataFromTableData[i].available){
718 $scope.canditateIds.push(dataFromTableData[i]);
719 $scope.chosenIds.splice(i,1);
728 function getParameterByName(name) {
729 name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
730 var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
731 results = regex.exec(location.search);
732 return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
735 app.directive("time", function() {
737 // replace custom element with html5 markup
738 template: '<div style="height:80px; display:inline-block;"> '
739 + ' <input type="text" class="fn-ebz-text" ng-model="timeStr" placeholder="HH:MM" style="width:70px" ng-change="parseValue()"/>'
740 + ' <div class="form-field" att-select="ampmOptions" ng-model="ampm" style="width:70px" ng-change="parseValue()"></div>'
743 // restrict usage to element only since we use attributes for APIs
750 link: function(scope, iElement, attrs){
753 controller: function ($scope) {
756 var am ={index: 0, value: 'AM', title: 'AM', alias:'Name2'};
757 var pm = {index: 1, value: 'PM', title: 'PM', alias:'Name'};
762 $scope.parseTimeStr= function(str){
766 if(/^(\d*):(\d*)$/.test(str)){
767 var hh = Number(str.match(/^(\d+)/)[1]);
768 var mm = Number(str.match(/:(\d+)/)[1]);
769 date = new Date(1970, 0, 1, hh, mm, 0);
771 date = new Date(str);
773 var hours = date.getHours();
774 var minutes = date.getMinutes();
775 var ampm = hours >= 12 ?pm : am;
777 hours = hours ? hours : 12; // the hour '0' should be '12'
778 minutes = minutes < 10 ? '0'+minutes : minutes;
779 hours = hours < 10 ? '0'+hours : hours;
780 var strTime = hours + ':' + minutes ;
783 $scope.timeStr =strTime;
785 if (typeof $scope.validTime != 'undefined'){
786 $scope.validTime=true;
789 if (typeof $scope.validTime != 'undefined'){
790 $scope.validTime=false;
794 $scope.timeStr = "12:00";
798 $scope.parseTimeStr($scope.value);
799 $scope.parseValue = function(){
802 var hh = Number($scope.timeStr.match(/^(\d+)/)[1]);
803 var mm = Number($scope.timeStr.match(/:(\d+)/)[1]);
805 if(hh<=12 && hh>0 && mm>=0 && mm<=59){
807 if($scope.ampm.value=='PM'&& hh<12) hh = hh+12;
808 if($scope.ampm.value=='AM'&& hh==12) hh = hh-12;
809 mm = mm < 10 ? '0'+mm : mm;
810 hh = hh < 10 ? '0'+hh : hh;
811 $scope.value= hh+":"+mm;
812 if (typeof $scope.validTime != 'undefined'){
813 $scope.validTime=true;
816 if (typeof $scope.validTime != 'undefined'){
817 $scope.validTime=false;
822 if (typeof $scope.validTime != 'undefined'){
823 $scope.validTime=false;