Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / static / js / search.js
1
2  
3   
4  app.directive('afterRender', [ function() {
5     var def = {
6         restrict : 'A', 
7         terminal : true,
8         transclude : false,
9         link : function(scope, element, attrs) {
10             if (attrs) { scope.$eval(attrs.afterRender) }
11             scope.$emit('onAfterRender')
12         }
13     };
14     return def;
15     }]);
16     
17  app.directive("search", function() {
18         return {
19                 // replace custom element with html5 markup
20             template: '<div >'    
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>   '                                                              
26                 + '      </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> ' 
29                 + '       </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" >  '                      
32                 + '      </div>  ' 
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;">&nbsp;</button>'           
37                 + '       </div>'  
38                 + '     </div>  '             
39                 + '</div>' 
40                 + '</div> ' ,
41             replace: true,
42             // restrict usage to element only since we use attributes for APIs
43             restrict: 'EA',
44             require: 'ngModel',
45             // new isolate scope
46             scope: {
47                 mSearch : '=ngModel'
48                 ,updateparent: '&'
49                 ,jsonForOption : '='
50                 ,jsonForOperator : '='  
51                 ,searchId : '=' 
52               },
53              link: function(scope, iElement, iAttrs){ 
54                  scope.optionsSizeArray = [];
55                  scope.sId = '';
56                  //scope.options = JSON.parse(JSON.stringify(iAttrs.jsonForOption));
57                  //scope.operators = JSON.parse(iAttrs.operators);
58                  
59                  scope.$watch("jsonForOption", function(newval, oldval) {
60                          scope.options = JSON.parse(JSON.stringify(oldval));
61                          console.log('1');
62                          scope.evalRepeatIndex(scope.options.length);
63                          console.log('2');
64
65                         });
66                  
67                  scope.evalRepeatIndex = function(size){
68                         for(index = 0; index < size; index++) {
69                          scope.optionsSizeArray.push(index);
70                         }
71                  };
72                  
73                  scope.$watch("jsonForOperator", function(newval, oldval) {
74                          scope.operators = JSON.parse(JSON.stringify(oldval));
75                 
76                         });
77                  
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'};
87                          }
88                  }
89                  scope.$watch("searchId", function(newval, oldval) {
90                          scope.sId = oldval;
91                          scope.hideDiv();
92                         });
93                  
94                  scope.showHide = function(div){
95                         if(div != 0){
96                                 $("#s1").css('display', 'none');
97                         }
98                          return true; 
99                  };
100                  
101                  
102                  scope.hideDiv = function(){
103                          console.log('3');
104                          console.log(scope.optionsSizeArray);
105
106
107                          for (i = 1; i < scope.optionsSizeArray.length; i++) {
108                                  var element = "#"+scope.sId+i;
109                                 $(element).css('display', 'none');
110                          }
111
112                          console.log('4');
113
114                 };
115                  
116                  
117                  $(function() {
118                                         scope.hideDiv();
119                                 });
120                  
121                 },
122              
123              controller: function ($scope) {
124                 
125                  $scope.addSearch = function(searchId, index, optionsLength){
126                          console.log('5');
127
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');   
132                                                  break;
133                                          }
134                                   };
135                                  console.log('6');
136
137                         };
138                  
139                         $scope.remove = function(searchId, index){ 
140                         var remove = "#"+searchId+index;        
141                         if(index!=0)
142                                         $(remove).css("display", "none");
143                                         var v  ={
144                                                         index: 0,
145                                                         value: '', 
146                                                         title: 'Select', 
147                                                         alias:''
148                                         };
149                                         $scope.valueOptions[index]=v;
150                                         $scope.compareOptions[index]=v;
151                                         $scope.searchValue[index]="";
152                     };
153          
154                     $scope.search = function() {        
155                                 var data = {
156                                         valueOptions                            : $scope.valueOptions,
157                                         compareOptions                          : $scope.compareOptions,
158                                         searchValue                                     : $scope.searchValue
159                          };
160                     };
161                     
162                     var data = {
163                                 valueOptions                            : $scope.valueOptions,
164                                 compareOptions                          : $scope.compareOptions,
165                                 searchValue                                     : $scope.searchValue
166                  };     
167                     
168                     $scope.mSearch = data;
169                     $scope.valueOptions=[];
170                         $scope.compareOptions=[];
171                         $scope.searchValue=[];
172              }
173         }
174   
175   });
176
177   app.directive('phoneNumberMask', [function(){
178                 return {
179                         restrict: 'A',
180                         require: '?ngModel',
181                         scope: {
182                                 ngModel : '='
183                         },
184                     link: function(scope, el, attrs){
185                         scope.$watch(attrs.phoneNumberMask, function(newValue, oldValue) {
186                                 
187                                 if(scope.ngModel)
188                                         scope.ngModel= scope.ngModel.replace(/(\+1)?(\d{3})(\d{3})(\d{4})/, '$2.$3.$4');
189                          $(el).mask("999.999.9999");
190                     });      
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');
195                         
196                       });
197                     },
198                 };
199         }]);
200   
201   app.directive('allowOnlyNumber', [function(){
202           return {
203                      require: 'ngModel',
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);
210                               modelCtrl.$render();
211                            }         
212
213                            return transformedInput;         
214                        });
215                      }
216                    };
217         }]);
218   
219   app.directive('showProcessing', function(){
220       return {
221           restrict: 'A',
222           link: function(scope, elem, attrs) {
223                   elem.bind('click', function() {
224                                 $(".overlayed").css("display","inline");
225                                 $(".loadingId").css("display","inline");
226                   });
227           }
228        }      
229     });
230  
231 app.directive("searchCriteria", function() {
232                 return {
233                         // replace custom element with html5 markup
234                     template: '<div >'    
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>   '                                                              
238                         + '      </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> ' 
241                         + '       </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> ' 
245                         + '      </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;">&nbsp;</button>'    
250                         + '       </div>'  
251                         + '     </div>  '             
252                         + '</div> ' ,
253                     replace: true,
254                     // restrict usage to element only since we use attributes for APIs
255                     restrict: 'EA',
256                     require: 'ngModel',
257                     // new isolate scope
258                     scope: {
259                         mSearch : '=ngModel',
260                         updateparent: '&'
261                         ,options : '=jsonForOption'
262                         ,operators : '=jsonForOperator'
263                       },
264                    
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 = [];
274                         //init 
275                         $scope.insertEmptyOption = function(arr){
276                                 var hasEmpty = false;
277                                  $.each(arr, function(i, a){ 
278                                          if(a.value ===''){
279                                                  hasEmpty = true;
280                                          }
281                                  });
282                                  if(!hasEmpty){
283                                          $.each(arr, function(i, a){ 
284                                                  a.index +=1;
285                                          });
286                                         arr.unshift({index: 0, value: '', title: 'Select', alias:'Select'});
287                                  }
288                         };
289                         $scope.findFirstOption = function(arr){
290                                 
291                         };
292                         $scope.insertEmptyOption($scope.options);
293                         $scope.insertEmptyOption($scope.operators);
294                         
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);
303                                                          var valueArr = [];
304                                                          $scope.availableValues.push(valueArr);
305                                                          $scope.availableOptions.push($scope.options);
306                                                          $scope.isShown.push(false);
307                                                  }
308                                          }else{
309                                                  $scope.searchCriterion.push("");
310                                                  $scope.availableOperators.push($scope.operators);
311                                                  var valueArr = [];
312                                                  $scope.availableValues.push(valueArr);
313                                                  $scope.availableOptions.push($scope.options);
314                                                  $scope.isShown.push(false);
315                                          }
316                                  }
317                          }
318                          $scope.isShown.pop();
319                         
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){ 
324                                                  if(a){
325                                                          var v = a.value;
326                                                          if(v){
327                                                                  var s=  $.grep(selectedOptions, function(e){ return e.value === v });
328                                                         
329                                                                  if(s.length ===1){
330                                                                         s[0].occurs += 1;
331                                                                  }else{
332                                                                          selectedOptions.push({value: v, occurs:1});
333                                                                  }
334                                                          }
335                                                          var o=  $.grep($scope.options, function(e){ return e.value === v });
336                                                          if(o.length ===1){
337                                                                 if("operators" in o[0]){
338                                                                         $scope.availableOperators[i]=o[0].operators;
339                                                                         $scope.insertEmptyOption($scope.availableOperators[i]);
340                                                                 }else{
341                                                                         $scope.availableOperators[i]=$scope.operators;
342                                                                 }
343                                                                 if("values" in o[0]){
344                                                                         $scope.availableValues[i]=o[0].values;
345                                                                 }else{
346                                                                         $scope.availableValues[i]=[];
347                                                                 }
348                                                          }
349                                                  }
350                                                 });
351                                         for(var j = 0 , l = $scope.availableOptions.length; j<l ; j++){
352                                                  var newOptions = [];
353                                                  var aoi = 0;
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 
358                                                          }else{
359                                                                  newOptions.push({index: aoi, value: a.value, title: a.title, alias:a.alias});
360                                                                  aoi += 1;
361                                                          }
362                                                  });
363                                                  $scope.availableOptions[j] = newOptions;
364                                                  if(isFirst){
365                                                          if($scope.availableValues[j].length>0)
366                                                                  $scope.searchValue[j]= $scope.availableValues[j][0];
367                                                          else
368                                                                  $scope.searchValue[j]="";
369                                                          
370                                                          $scope.compareOptions[j]= $scope.availableOperators[j][0];
371                                                  }
372                                                 };
373                                         
374                                  }
375                                  if(typeof index !== 'undefined' && !isFirst){
376                                          if($scope.availableValues[index].length>0)
377                                                  $scope.searchValue[index]= $scope.availableValues[index][0];
378                                          else
379                                                  $scope.searchValue[index]="";
380                                  }
381                          };
382                          
383                          $scope.updateAvailableOptions(undefined, true);
384                          $.each($scope.availableOptions, function(j, a){ 
385                                  $scope.valueOptions[j]= a[0];
386                          });
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;
391                                                 break;
392                                         }
393                                         
394                                 }
395                         };
396                         
397                         $scope.removeSearchCriteria = function(index){
398                                 $scope.isShown[index]= false;
399                                 
400                                 
401                                         $scope.valueOptions[index]=$scope.availableOptions[index][0];
402                                         $scope.compareOptions[index]=$scope.availableOperators[index][0];
403                                         $scope.searchValue[index]="";
404                         };
405                             $scope.search = function() {
406                                 //remove empty criteria
407                                         var vo =[];
408                                 var co =[];
409                                 var sv =[];
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 === ''){
412                                         }else{
413                                                 vo.push($scope.valueOptions[i]);
414                                                 co.push($scope.compareOptions[i]);
415                                                 sv.push($scope.searchValue[i]);
416                                         }
417                                 }
418                                 $scope.updateparent({filter: { valueOptions: vo, compareOptions: co, searchValue :sv }  });
419                             };
420                             
421                             $scope.$watchCollection("valueOptions", function(collection, oldValue ){
422                                   if(collection) {
423                                           var index;
424                                           for(var i = 0 , l =collection.length; i<l; i++ ){
425                                                         if(!oldValue[i] || oldValue[i].value!=collection[i].value){
426                                                                 index = i;
427                                                                 break;
428                                                         }
429                                                         
430                                                 }
431                                           $scope.updateAvailableOptions(index);
432                                           }
433                                         }, true);
434                                 
435                      }
436                 }
437           
438           });
439    
440  app.directive("selectUser", function() {
441                 return {
442                         // replace custom element with html5 markup
443                     template: '<div>            '
444                         + '<table style="width:660px; margin-left:-12px;" >'
445                         + '<thead>'
446                         + '  <tr >'
447                         + '   <th style="width:325px;">{{availableTitle}}</th> '
448                         + '    <th style="width:10px;"></th>        '
449                         + '    <th style="width:325px;">{{userTitle}}</th> '        
450                         + '</tr>'
451                         + '</thead>'
452                         + '<tbody>'
453                         + '<tr>'
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/>'
458                         + '   </label>'
459                         + '  </div>'
460                         + '</td>'
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"/>'
464                         + '     <br/><br/> '
465                         + '     <img src="static/images/leftarrow_g.png" id="chooseBtn"  ng-click="removeSelected()" ng-hide="oneMax"/>'
466                         + '      <br/><br/>'
467                         + '      <img  id="chooseAllBtn"  src="static/images/rightrightarrow_g.png"  ng-click="chooseAll()" ng-hide="oneMax"/>'
468                         + '     <br/><br/>'
469                         + '    <img style="cursor:pointer" id="removeAllBtn" src="static/images/leftleftarrow_g.png"  ng-click="removeAll()" ng-hide="oneMax"/>'
470                         + '</td>'
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/>'
475                         + '        </label>'
476                         + '     </div>'
477                         + '</td> '
478                         + ' </tr>'
479                         + '</tbody>'
480                         + '</table>'    
481                         + '</div>',
482                     replace: true,
483                     // restrict usage to element only since we use attributes for APIs
484                     restrict: 'EA',
485                     // new isolate scope
486                     scope: {
487                         chosenIds  : '=assignedUsers'   
488                         ,availableUsers : '='   
489                         ,userTitle : '='        
490                         ,availableTitle : '='   
491                         ,oneMax : '=?'
492                       },
493                      link: function(scope, iElement, attrs){ 
494                         
495                          scope.$watch("userTitle", function(newval, oldval) {
496                                  scope.userTitle = newval;
497                                 });
498                          scope.$watch("availableTitle", function(newval, oldval) {
499                                  scope.availableTitle = newval;
500                                 });
501                          
502                          scope.$watch("availableUsers", function(newval, oldval) {
503                                  scope.availableUsers = newval;
504                                  scope.canditateIds= scope.getArrayRemoved(scope.availableUsers, scope.chosenIds);
505                                 });
506                          
507                         },
508                      
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; });
515                                                 };
516                                         }
517                                         return retArray;
518                                 };
519                          $scope.canditateIds= $scope.getArrayRemoved($scope.availableUsers, $scope.chosenIds);
520                          $scope.chooseAll = function() {
521                                  
522                                  var dataFromTableData = $scope.canditateIds;
523                                          for (var i = dataFromTableData.length - 1; i >= 0; i--){       
524                                                  if(!$scope.chosenIds)
525                                                  $scope.chosenIds=[];
526                                                   $scope.chosenIds.push(dataFromTableData[i]);
527                                               $scope.canditateIds.splice(i,1);
528                                                   
529                                            }
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;
534                                                     }
535                                                 }
536                          };
537                         
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);
543                                           
544                                    } 
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;
549                                             }
550                                         }
551                          };
552                          
553                         $scope.chooseSelected = function() {
554                                 
555                                         var dataFromTableData = $scope.canditateIds;
556                                         
557                                                         for (var i = dataFromTableData.length - 1; i >= 0; i--){         
558                                           
559                                           if(dataFromTableData[i].available){
560                                                   if(!$scope.chosenIds)
561                                                          $scope.chosenIds=[];
562                                                   $scope.chosenIds.push(dataFromTableData[i]);
563                                                   $scope.canditateIds.splice(i,1);
564                                                   
565                                          } 
566                                  }
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;
571                                                             }
572                                                         }
573                          };
574                          $scope.removeSelected = function() {
575                                         
576                                          var dataFromTableData = $scope.chosenIds;
577                                         
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);
582                                                         
583                                                          } 
584                                                  } ;
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;
589                                                             }
590                                                         }
591                          };
592                          $scope.checkCanditate = function(index) {
593                                  if($scope.oneMax){
594                                          for (var i = $scope.canditateIds.length - 1; i >= 0; i--){     
595                                                  if(i != index)
596                                               $scope.canditateIds[i].available=false;
597                                          }
598                                  }
599                          };
600                         
601                          
602                      }
603                 }
604         });
605  app.directive("selectString", function() {
606                 return {
607                         // replace custom element with html5 markup
608                     template: '<div>            '
609                         + '<table style="width:660px;">'
610                         + '<thead>'
611                         + '  <tr >'
612                         + '   <th style="width:325px;">{{availableTitle}}</th> '
613                         + '    <th style="width:10px;"></th>        '
614                         + '    <th style="width:325px;">{{assignedTitle}}</th> '        
615                         + '</tr>'
616                         + '</thead>'
617                         + '<tbody>'
618                         + '<tr>'
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/>'
623                         + '   </label>'
624                         + '  </div>'
625                         + '</td>'
626                         + '<td valign="middle" width="10px">'
627                         + '      <img src="static/images/rightarrow_g.png" id="removeBtn" ng-click="chooseSelected()" />'
628                         + '     <br/><br/> '
629                         + '     <img src="static/images/leftarrow_g.png" id="chooseBtn"  ng-click="removeSelected()" />'
630                         + '      <br/><br/>'
631                         + '      <img  id="chooseAllBtn"  src="static/images/rightrightarrow_g.png"  ng-click="chooseAll()" />'
632                         + '     <br/><br/>'
633                         + '    <img style="cursor:pointer" id="removeAllBtn" src="static/images/leftleftarrow_g.png"  ng-click="removeAll()" />'
634                         + '</td>'
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/>'
639                         + '        </label>'
640                         + '     </div>'
641                         + '</td> '
642                         + ' </tr>'
643                         + '</tbody>'
644                         + '</table>'    
645                         + '</div>',
646                     replace: true,
647                     // restrict usage to element only since we use attributes for APIs
648                     restrict: 'EA',
649                     // new isolate scope
650                     scope: {
651                         chosenIds  : '=assignedOptions' 
652                         ,availableOptions : '=' 
653                         ,availableTitle : '@'   
654                         ,assignedTitle : '@'    
655                       },
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);
660                                 });
661                          
662                         },
663                      
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]; });
670                                                 };
671                                         }
672                                         return retArray;
673                                 };
674                          
675                          $scope.canditateIds= $scope.getArrayRemoved($scope.availableOptions, $scope.chosenIds);
676                          $scope.chooseAll = function() {
677                                  
678                                  var dataFromTableData = $scope.canditateIds;
679                                          for (var i = dataFromTableData.length - 1; i >= 0; i--){       
680                                                  if(!$scope.chosenIds)
681                                                  $scope.chosenIds=[];
682                                                   $scope.chosenIds.push(dataFromTableData[i]);
683                                               $scope.canditateIds.splice(i,1);
684                                                   
685                                            } 
686                          };
687                         
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);
693                                           
694                                    } 
695                          };
696                          
697                         $scope.chooseSelected = function() {
698                                 
699                                         var dataFromTableData = $scope.canditateIds;
700                                         
701                                                         for (var i = dataFromTableData.length - 1; i >= 0; i--){         
702                                           
703                                           if(dataFromTableData[i].available){
704                                                   if(!$scope.chosenIds)
705                                                          $scope.chosenIds=[];
706                                                   $scope.chosenIds.push(dataFromTableData[i]);
707                                                   $scope.canditateIds.splice(i,1);
708                                                   
709                                          } 
710                                  } 
711                          };
712                          $scope.removeSelected = function() {
713                                         
714                                          var dataFromTableData = $scope.chosenIds;
715                                         
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);
720                                                         
721                                                          } 
722                                                  } ;
723                          };
724                          
725                      }
726                 }
727         });
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, " "));
733         };
734
735  app.directive("time", function() {
736                 return {
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>'
741                         + '     </div>',
742                     replace: true,
743                     // restrict usage to element only since we use attributes for APIs
744                     restrict: 'EA',
745                     // new isolate scope
746                     scope: {
747                         value  : '='
748                         ,validTime : '=?'
749                       },
750                      link: function(scope, iElement, attrs){ 
751                         },
752                      
753                      controller: function ($scope) {
754                          $scope.timeStr='';
755                          $scope.ampm=null;
756                          var am ={index: 0, value: 'AM', title: 'AM', alias:'Name2'};
757                          var pm = {index: 1, value: 'PM', title: 'PM', alias:'Name'};
758                          $scope.ampmOptions=[
759                                             am,
760                                             pm,
761                                                                         ]
762                          $scope.parseTimeStr= function(str){
763                                  if(str){
764                                         try{
765                                                 var date;
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);
770                                                 }else{
771                                                         date = new Date(str);
772                                                 }
773                                                   var hours = date.getHours();
774                                                   var minutes = date.getMinutes();
775                                                   var ampm = hours >= 12 ?pm : am;
776                                                   hours = hours % 12;
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 ;
781                                                  
782                                                  
783                                                    $scope.timeStr =strTime;
784                                                    $scope.ampm = ampm;    
785                                                    if (typeof $scope.validTime != 'undefined'){
786                                                                  $scope.validTime=true;
787                                                          }
788                                         }catch(err){
789                                                 if (typeof $scope.validTime != 'undefined'){
790                                                          $scope.validTime=false;
791                                                  }
792                                         }
793                                  }else{
794                                         $scope.timeStr = "12:00";
795                                         $scope.ampm =am;
796                                  }
797                          };
798                          $scope.parseTimeStr($scope.value);
799                         $scope.parseValue = function(){
800                                 try{
801                                         var date;
802                                         var hh = Number($scope.timeStr.match(/^(\d+)/)[1]);
803                                         var mm = Number($scope.timeStr.match(/:(\d+)/)[1]);
804                                         
805                                         if(hh<=12 && hh>0 && mm>=0 && mm<=59){
806                                                 
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;
814                                          }
815                                         }else{
816                                                 if (typeof $scope.validTime != 'undefined'){
817                                                          $scope.validTime=false;
818                                                  }
819                                         }
820                                         
821                                 }catch(err){
822                                         if (typeof $scope.validTime != 'undefined'){
823                                                  $scope.validTime=false;
824                                          }
825                                 }
826                         };
827                      }
828                 }
829         });