Initialize the UI code
[holmes/rule-management.git] / rulemgt / src / main / frontend / src / public / framework / browser / js / app.js
1 /*
2
3     Copyright 2016-2017, Huawei Technologies Co., Ltd.
4
5     Licensed under the Apache License, Version 2.0 (the "License");
6     you may not use this file except in compliance with the License.
7     You may obtain a copy of the License at
8
9             http://www.apache.org/licenses/LICENSE-2.0
10
11     Unless required by applicable law or agreed to in writing, software
12     distributed under the License is distributed on an "AS IS" BASIS,
13     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14     See the License for the specific language governing permissions and
15     limitations under the License.
16
17 */
18
19
20 var app = angular.module("POCApp", ["ui.router", "ngTable"])
21
22     /*.run(function($rootScope, $location, $state, LoginService) {
23         $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams){
24             if (toState.authenticate && !LoginService.isAuthenticated()){
25                 // User isn’t authenticated
26                 $state.transitionTo("login");
27                 event.preventDefault();
28             }
29         });
30     })*/
31     .config(function($stateProvider, $urlRouterProvider, $urlMatcherFactoryProvider){
32         //$routeProvider.caseInsensitiveMatch = true;
33         $urlMatcherFactoryProvider.caseInsensitive(true);
34         $urlRouterProvider.otherwise('/login');
35         //$locationProvider.html5Mode(true).hashPrefix('!');
36         $stateProvider
37             .state('login', {
38                 url : '/login',
39                 templateUrl : 'templates/login.html',
40                 controller : 'LoginController',
41                 authenticate: false
42             })
43             .state('register', {
44                 url : '/register',
45                 templateUrl : 'templates/register.html',
46                 controller : 'registerController',
47                 authenticate: false
48             })
49             .state("home", {
50                 url: "/home",
51                 templateUrl : "templates/home.html",
52                 controller : "homeCtrl",
53                 authenticate: true
54             })
55             .state("home.tree", {
56                 url: "/tree",
57                 templateUrl : "templates/tree.html",
58                 controller : "treeCtrl",
59                 authenticate: true
60             })
61             .state("home.accordion", {
62                 url: "/accordion",
63                 templateUrl : "templates/accordion.html",
64                 controller : "accordionCtrl",
65                 authenticate: true
66             })
67             .state("home.tabs", {
68                 url: "/tabs",
69                 templateUrl : "templates/tabs.html",
70                 controller : "tabsCtrl",
71                 authenticate: true
72             })
73             .state("home.vtabs", {
74                 url: "/vtabs",
75                 templateUrl : "templates/verticalTab.html",
76                 controller : "vTabCtrl",
77                 authenticate: true
78             })
79             .state("home.table", {
80                 url: "/table",
81                 templateUrl : "templates/table.html",
82                 controller : "tableCtrl",
83                 authenticate: true
84             })
85             .state("home.buttons", {
86                 url: "/buttons",
87                 templateUrl : "templates/buttons.html",
88                 controller : "buttonsCtrl",
89                 authenticate: true
90             })
91             /*state for radio button and checkboxes-------------------------------------------------*/
92             .state("home.radiobuttons", {
93                 url: "/radiobuttons",
94                 templateUrl : "templates/radioButtons.html",
95                 controller : "radioCtrl",
96                 authenticate: true
97             })
98             .state("home.checkboxes", {
99                 url: "/checkboxes",
100                 templateUrl : "templates/checkBoxes.html",
101                 controller : "checkBoxCtrl",
102                 authenticate: true
103             })
104             .state("home.dropdown", {
105                 url: "/dropdown",
106                 templateUrl: "templates/dropdown.html",
107                 controller: "dropdownCtrl",
108                 authenticate: true
109             })
110
111             .state("home.list", {
112                 url: "/list",
113                 /*template:"<h3>Under Progress</h3>",*/
114                 templateUrl : "templates/list.html",
115                 controller : "listCtrl",
116                 authenticate: true
117             })
118
119             .state("home.provinceMgmt", {
120                 url: "/management",
121                 templateUrl : "templates/management.html",
122                 controller : "managementCtrl",
123                 authenticate: true
124             })
125             .state("home.tooltip", {
126                 url: "/textarea",
127                 templateUrl : "templates/textarea.html",
128                 controller : "toolCtrl",
129                 authenticate: true
130             })
131
132             .state("home.notification", {
133                 url: "/notification",
134                 templateUrl : "templates/notification.html",
135                 controller : "notificationCtrl",
136                 authenticate: true
137             })
138             .state("home.functional", {
139                 url: "/functional",
140                 templateUrl : "templates/functional.html",
141                 controller : "functionalCtrl",
142                 authenticate: true
143             })
144
145
146     })
147     .controller('LoginController', function($scope, $rootScope, $stateParams, $state, LoginService) {
148         $rootScope.title = "AngularJS Login Sample";
149
150         $scope.formSubmit = function() {
151             LoginService.login($scope.user)
152                 .then(function (data) {
153                     if (data) {
154                         $scope.error = '';
155                         $scope.user.username = '';
156                         $scope.user.password = '';
157                         $state.transitionTo('home.tree');
158                     }
159                     else {
160                         $scope.error = "Incorrect username/password !";
161                     }
162                 }, function (reason) {
163                     $scope.error = "Incorrect username/password !";
164                 });
165         };
166
167     })
168     .controller('registerController', function($scope, $state, LoginService){
169         $scope.formSubmit = function() {
170             if($scope.user.password === $scope.user.confpassword) {
171                 LoginService.registerUser($scope.user)
172                     .then(function (data) {
173                         $state.transitionTo("login");
174                     }, function () {
175                         console.log("Failed to register");
176                     });
177             }
178             else {
179                 console.log("Password not matched...");
180                 var dialog_tpl = $(modelTemplate).filter('#personDialog').html();
181                 var data = {'title':'Error',showClose:true, 'closeBtnTxt':'Ok', 'icon':'glyphicon glyphicon-exclamation-sign','iconColor':'icon_error','msg':'Password and Confirm password does not match.', buttons:[]};
182                 var html = Mustache.to_html(dialog_tpl, data);
183                 $(html).modal({backdrop: "static"});   //backdrop: "static" - for grayed out and no outside click work, backdrop: false - no grayed out*/
184             }
185         };
186     })
187     .controller("homeCtrl", function($scope, $state, DataService){
188         $scope.message = "Home Page";
189
190         /*$scope.geticonClass = function() {
191             if($( "#panel1" ).hasClass( "in" )){
192                 return "openo_accordion_ui-icon-expand";
193             }
194             else{
195                return "openo_accordion_ui-icon-expand.current";
196             }
197
198
199         }*/
200
201
202
203         /* $scope.accordionLoaded  = function() {
204              if(modelTemplate != null) {
205                  console.log("left menu loading..");
206                  menuaccordion();
207                  return true;
208              }
209              console.log("left menu not loading..");
210              return false;
211          }
212
213          function menuaccordion() {
214              var accordion_tpl = $(modelTemplate).filter('#menu_accordion').html();
215
216              $.getJSON('./data/homelinks.json', function (accordion) {
217                  var html = Mustache.to_html(accordion_tpl, accordion.accordion_data);
218                  $('#accordionmenuid').html(html);
219              });
220          }*/
221
222     })
223
224     /* Tree Controller */
225     .controller("treeCtrl", function($scope,DataService,$log){
226         $scope.message = "Tree Data";
227         var setting = {};
228         /*$scope.treeLoaded = function() {
229             if(modelTemplate != null) {
230                 console.log("Tree data loading..");
231                 tree();
232                 return true;
233             }
234             console.log("Tree data not loading..");
235             return false;
236         }*/
237         $scope.init = function() {
238             $scope.param="treeData";
239             $scope.shortNote="shortNote";
240             DataService.getAllData($scope.param)
241                 .then(function(data){
242                     $scope.treeData = data;
243                     tree();
244                     console.log("inside tree");
245                     $log.info($scope.treeData);
246                 });
247             DataService.getAllData($scope.shortNote)
248                 .then(function(data1){
249                     $scope.treeTip = data1.treeTip;
250                     console.log("inside treeTip");
251                     $log.info(data1);
252                 });
253         }
254         function tree() {
255             zNodes = $scope.treeData;
256             $.fn.zTree.init($("#tree1"), setting, zNodes);
257
258         }
259     })
260
261     /* Accordian Controller */
262     .controller("accordionCtrl", function($scope,DataService, $log){
263
264         $scope.message = "Accordion";
265
266         $scope.accordionLoaded  = function() {
267             if(modelTemplate != null) {
268                 console.log("accordion loading..");
269
270                 accordion();
271                 return true;
272             }
273             console.log("accordion not loading..");
274             return false;
275         }
276
277         $scope.init = function() {
278             $scope.param="accordionData";
279             $scope.accordionTip="shortNote";
280             DataService.getAllData($scope.param)
281                 .then(function(data){
282                     $scope.accordion = data;
283                     accordion();
284                     console.log("inside accordion");
285                     $log.info(data);
286                 });
287             DataService.getAllData($scope.accordionTip)
288                 .then(function(data){
289                     $scope.accordionTipData = data.accordionTip;
290                     console.log("inside accordion");
291                     $log.info(data);
292                 });
293         }
294
295         function accordion() {
296
297             var accordion_tpl = $(modelTemplate).filter('#accordion').html();
298             console.log("in acc" );
299             var html = Mustache.to_html(accordion_tpl, $scope.accordion.accordion_data);
300             $('#accordion').html(html);
301         }
302     })
303     .controller("tabsCtrl", function($scope, $state, DataService, $log){
304         $scope.message = "Tabs";
305         $scope.tabLoaded  = function() {
306             if(modelTemplate != null) {
307                 console.log("Tab is loading..");
308                 loadTabData();
309                 return true;
310             }
311             console.log("Not ready..");
312             return false;
313         }
314
315         $scope.init = function() {
316             $scope.param="tabData";
317             $scope.tabTip="shortNote";
318             DataService.getAllData($scope.param)
319                 .then(function(data){
320                     $scope.tabdata = data;
321                     loadTabData();
322                     console.log("inside tabs");
323                     $log.info(data);
324                 });
325             DataService.getAllData($scope.tabTip)
326                 .then(function(data){
327                     $scope.tabTipData = data.tabTip;
328                     $log.info(data);
329                 });
330         }
331
332         function loadTabData() {
333             var tab_tpl = $(modelTemplate).filter('#tabs').html();
334             var html = Mustache.to_html(tab_tpl, $scope.tabdata.tabData);
335             $('#tabArea').html(html);
336         }
337
338     })
339     .controller("vTabCtrl", function($scope, $state, DataService){
340         $scope.message = "Vertical Tabs";
341
342         $scope.vtabLoaded  = function() {
343             if(modelTemplate != null) {
344                 console.log("Vertical Tab is loading..");
345                 loadvTabData();
346                 return true;
347             }
348             console.log("Not ready..");
349             return false;
350         }
351
352         $scope.init = function() {
353             $scope.param="vtabData";
354             $scope.vtabTip="shortNote";
355             DataService.getAllData($scope.param)
356                 .then(function(vtabdata){
357                     $scope.data = vtabdata;
358                     loadvTabData();
359                     console.log("inside vTab");
360                 });
361             DataService.getAllData($scope.vtabTip)
362                 .then(function(vtabdata){
363                     $scope.vtabTipdata = vtabdata.vtabTip;
364                     console.log("inside vTab");
365                 });
366         }
367
368         function loadvTabData() {
369
370             var vtab_tpl = $(modelTemplate).filter('#vtabs').html();
371             var html = Mustache.to_html(vtab_tpl, $scope.data.vtabData);
372             $('#vtabArea').html(html);
373         }
374     })
375     .controller("tableCtrl", function($scope, $state, DataService){
376         $scope.message = "Tables";
377
378         $scope.tableLoaded  = function() {
379             if(modelTemplate != null) {
380                 console.log("Table is loading..");
381                 loadTableData();
382                 return true;
383             }
384             console.log("Not ready..");
385             return false;
386         }
387
388         $scope.init = function() {
389             $scope.param="tableData";
390             $scope.tableTip="shortNote";
391             DataService.getAllData($scope.param)
392                 .then(function(data){
393                     $scope.tableData = data;
394                     loadTableData();
395                     console.log("inside table");
396                 });
397
398             DataService.getAllData($scope.tableTip)
399                 .then(function(data){
400                     $scope.tableTipData = data.tableTip;
401                     console.log("inside table");
402                 });
403         }
404
405         function loadTableData() {
406
407             var table_tpl = $(modelTemplate).filter('#table').html();
408
409             var html = Mustache.to_html(table_tpl, $scope.tableData.basic_table_data);
410             $('#basictableArea').html(html);
411
412             var html = Mustache.to_html(table_tpl, $scope.tableData.str_table_data);
413             $('#strippedtableArea').html(html);
414
415             var html = Mustache.to_html(table_tpl, $scope.tableData.cond_table_data);
416             $('#condensedtableArea').html(html);
417         }
418     })
419
420     /* Buttons Controller */
421     .controller("buttonsCtrl", function($scope,DataService,$log){
422         $scope.message = "Types of Buttons";
423         $scope.buttonTip="shortNote";
424
425         $scope.init = function() {
426             $scope.param="buttonsData";
427             DataService.getAllData($scope.param)
428                 .then(function(data){
429                     $scope.buttons = data;
430                     defaultButtons();
431                     visualButtons();
432                     sizeButtons();
433                     iconButtons();
434                     console.log("inside accordion");
435                     $log.info(data);
436                 });
437             DataService.getAllData($scope.buttonTip)
438                 .then(function(data){
439                     $scope.buttonTipData = data.buttonTip;
440                     console.log("inside table");
441                 });
442         }
443
444         function defaultButtons(){
445             console.log("Default buttons Loaded..");
446             //Here your view content is fully loaded !!
447             var def_button_tpl = $(modelTemplate).filter('#defaultButtons').html();
448             var def_icon_button_tpl = $(modelTemplate).filter('#defaultIconButtons').html();
449
450             var html = Mustache.to_html(def_button_tpl, $scope.buttons.default_btn_data.def_button);
451             $('#defaultButtonArea').html(html);
452
453             var html = Mustache.to_html(def_icon_button_tpl, $scope.buttons.default_btn_data.def_print_button);
454             $('#defaultButtonArea').append(html);
455
456             var html = Mustache.to_html(def_icon_button_tpl, $scope.buttons.default_btn_data.def_print_button_right);
457             $('#defaultButtonArea').append(html);
458         }
459
460
461         function visualButtons(){
462             console.log("Loaded..");
463             //Here your view content is fully loaded !!
464             var visual_button_tpl = $(modelTemplate).filter('#visualButtons').html();
465
466             var html = Mustache.to_html(visual_button_tpl, $scope.buttons.visual_btn_data.vis_pri_btn_data);
467             $('#visualButtonArea').html(html);
468
469             var html = Mustache.to_html(visual_button_tpl, $scope.buttons.visual_btn_data.vis_sec_btn_data);
470             $('#visualButtonArea').append(html);
471
472             var html = Mustache.to_html(visual_button_tpl, $scope.buttons.visual_btn_data.vis_succ_btn_data);
473             $('#visualButtonArea').append(html);
474
475             var html = Mustache.to_html(visual_button_tpl, $scope.buttons.visual_btn_data.vis_inf_btn_data);
476             $('#visualButtonArea').append(html);
477
478             var html = Mustache.to_html(visual_button_tpl, $scope.buttons.visual_btn_data.vis_warn_btn_data);
479             $('#visualButtonArea').append(html);
480
481             var html = Mustache.to_html(visual_button_tpl, $scope.buttons.visual_btn_data.vis_dang_btn_data);
482             $('#visualButtonArea').append(html);
483
484             var html = Mustache.to_html(visual_button_tpl, $scope.buttons.visual_btn_data.vis_link_btn_data);
485             $('#visualButtonArea').append(html);
486         }
487
488         function sizeButtons() {
489             var size_button_tpl = $(modelTemplate).filter('#sizeButtons').html();
490
491             var html = Mustache.to_html(size_button_tpl, $scope.buttons.diffSize_btn_data.size_small_btn_data);
492             $('#sizeButtonArea').html(html);
493
494             var html = Mustache.to_html(size_button_tpl, $scope.buttons.diffSize_btn_data.size_large_btn_data);
495             $('#sizeButtonArea').append(html);
496
497             var html = Mustache.to_html(size_button_tpl, $scope.buttons.diffSize_btn_data.size_block_btn_data);
498             $('#sizeButtonArea').append(html);
499
500         }
501
502         function iconButtons() {
503             var icon_button_tpl = $(modelTemplate).filter('#iconButtons').html();
504
505             var html = Mustache.to_html(icon_button_tpl, $scope.buttons.icon_btn_data.search_icon_btn_data);
506             $('#iconButtonArea').html(html);
507
508             var html = Mustache.to_html(icon_button_tpl, $scope.buttons.icon_btn_data.search_icon_styled_btn_data);
509             $('#iconButtonArea').append(html);
510
511             var html = Mustache.to_html(icon_button_tpl, $scope.buttons.icon_btn_data.print_icon_btn_data);
512             $('#iconButtonArea').append(html);
513
514         }
515
516         $scope.defaultButtonsLoaded  = function() {
517             if(modelTemplate != null) {
518                 console.log("default buttons loading..");
519                 defaultButtons();
520                 return true;
521             }
522             console.log("default buttons not loading..");
523             return false;
524         }
525
526         $scope.visualButtonsLoaded  = function() {
527             if(modelTemplate != null) {
528                 console.log("visual buttons loading..");
529                 visualButtons();
530                 return true;
531             }
532             console.log("visual buttons not loading..");
533             return false;
534         }
535
536         $scope.sizeButtonsLoaded  = function() {
537             if(modelTemplate != null) {
538                 console.log("size buttons loading..");
539                 sizeButtons();
540                 return true;
541             }
542             console.log("size buttons not loading..");
543             return false;
544         }
545
546         $scope.iconButtonsLoaded  = function() {
547             if(modelTemplate != null) {
548                 console.log("icon buttons loading..");
549                 iconButtons();
550                 return true;
551             }
552             console.log("icon buttons not loading..");
553             return false;
554         }
555     })
556     /* Drop down----------------------*/
557     .controller("dropdownCtrl", function($scope, DataService) {
558         $scope.message = "You selected drop down";
559         $scope.subIsLoaded = function () {
560             if (modelTemplate != null) {
561                 console.log("Loading..");
562                 loadDrop();
563                 return true;
564             }
565             console.log("Not Loaded..");
566             return false;
567         }
568
569         $scope.init = function() {
570             $scope.param="dropdownData";
571             $scope.dropdownTip="shortNote";
572             DataService.getAllData($scope.param)
573                 .then(function(data){
574                     $scope.dropdown = data;
575                     loadDrop();
576                 });
577             DataService.getAllData($scope.dropdownTip)
578                 .then(function(data){
579                     $scope.dropdownTipData = data.dropdownTip;
580                     console.log("inside table");
581                 });
582         }
583         function loadDrop() {
584             var drop_tpl = $(modelTemplate).filter('#dropDown').html();
585             var dropHeader_tpl = $(modelTemplate).filter('#dropDownHeader').html();
586             var dropSimple_tpl = $(modelTemplate).filter('#simpleDropdownTmpl').html();
587
588             var html = Mustache.to_html(drop_tpl, $scope.dropdown.dropped_down_data);
589             $('#dropArea').html(html);
590
591             var html = Mustache.to_html(drop_tpl, $scope.dropdown.dropped_up_data);
592             $('#dropAreaUP').html(html);
593
594             var html = Mustache.to_html(dropHeader_tpl, $scope.dropdown.dropHeader_data);
595             $('#dropAreaHeader').html(html);
596
597             var html = Mustache.to_html(dropSimple_tpl, $scope.dropdown.dropSimple_data);
598             $('#plainDropDown').html(html);
599
600         }
601     })
602     .controller("radioCtrl", function($scope, DataService, $log) {
603         $scope.message = "You selected radio button tab";
604         var lodedOnce = false;
605         $scope.subIsLoaded  = function() {
606             if(modelTemplate != null) {
607                 console.log("Loading..");
608                 loadRadioBtn();
609                 return true;
610             }
611             console.log("Not Loaded..");
612             return false;
613         }
614
615         $scope.init = function() {
616             $scope.param="radioData";
617             $scope.radioTip="shortNote";
618             DataService.getAllData($scope.param)
619                 .then(function(data){
620                     $scope.radioButton = data;
621                     loadRadioBtn();
622                     console.log("inside button");
623                     $log.info(data);
624                 });
625
626             DataService.getAllData($scope.radioTip)
627                 .then(function(data){
628                     $scope.radioTipData = data.radioTip;
629                     console.log("inside table");
630                 });
631         }
632         function loadRadioBtn(){
633             console.log("lodedOnce : "+lodedOnce);
634
635             var radio_button_tpl = $(modelTemplate).filter('#radioButtons').html();
636             var html = Mustache.to_html(radio_button_tpl, $scope.radioButton .radio_btn_default_data);
637             $('#radioBtnArea').html(html);
638
639             var html = Mustache.to_html(radio_button_tpl, $scope.radioButton .radio_btn_primary_data);
640             $('#radioBtnArea').append(html);
641
642             var html = Mustache.to_html(radio_button_tpl, $scope.radioButton .radio_btn_success_data);
643             $('#radioBtnArea').append(html);
644
645             var html = Mustache.to_html(radio_button_tpl, $scope.radioButton .radio_btn_danger_data);
646             $('#radioBtnArea').append(html);
647
648             var html = Mustache.to_html(radio_button_tpl, $scope.radioButton .radio_btn_Warn_data);
649             $('#radioBtnArea').append(html);
650
651             var html = Mustache.to_html(radio_button_tpl, $scope.radioButton .radio_btn_info_data);
652             $('#radioBtnArea').append(html);
653
654         }
655     })
656     .controller("checkBoxCtrl", function($scope, DataService) {
657         $scope.message = "You selected checkbox tab";
658         $scope.subIsLoaded  = function() {
659             if(modelTemplate != null) {
660                 console.log("Loading..");
661                 loadCheckBox();
662                 return true;
663             }
664             console.log("Not Loaded..");
665             return false;
666         }
667         $scope.init = function() {
668             $scope.param="checkboxData";
669             $scope.checkboxTip="shortNote";
670             DataService.getAllData($scope.param)
671                 .then(function(data){
672                     $scope.checkBox = data;
673                     loadCheckBox();
674                 });
675             DataService.getAllData($scope.checkboxTip)
676                 .then(function(data){
677                     $scope.checkboxTipData = data.checkboxTip;
678                     console.log("inside table");
679                 });
680         }
681         function loadCheckBox() {
682             var check_box_tpl = $(modelTemplate).filter('#checkBoxes').html();
683
684             var html = Mustache.to_html(check_box_tpl, $scope.checkBox.checkbox_default_data);
685             $('#CheckBoxArea').html(html);
686
687             var html = Mustache.to_html(check_box_tpl, $scope.checkBox.checkbox_primary_data);
688             $('#CheckBoxArea').append(html);
689
690             var html = Mustache.to_html(check_box_tpl, $scope.checkBox.checkbox_success_data);
691             $('#CheckBoxArea').append(html);
692
693             var html = Mustache.to_html(check_box_tpl, $scope.checkBox.checkbox_danger_data);
694             $('#CheckBoxArea').append(html);
695
696             var html = Mustache.to_html(check_box_tpl, $scope.checkBox.checkbox_warn_data);
697             $('#CheckBoxArea').append(html);
698
699             var html = Mustache.to_html(check_box_tpl, $scope.checkBox.checkbox_info_data);
700             $('#CheckBoxArea').append(html);
701
702             /*$.getJSON('./data/checkboxData.json', function(c_data) {
703              var html = Mustache.to_html(check_box_tpl, c_data.checkbox_default_data);
704              $('#CheckBoxArea').html(html);
705
706              var html = Mustache.to_html(check_box_tpl, c_data.checkbox_primary_data);
707              $('#CheckBoxArea').append(html);
708
709              var html = Mustache.to_html(check_box_tpl, c_data.checkbox_success_data);
710              $('#CheckBoxArea').append(html);
711
712              var html = Mustache.to_html(check_box_tpl, c_data.checkbox_danger_data);
713              $('#CheckBoxArea').append(html);
714
715              var html = Mustache.to_html(check_box_tpl, c_data.checkbox_warn_data);
716              $('#CheckBoxArea').append(html);
717
718              var html = Mustache.to_html(check_box_tpl, c_data.checkbox_info_data);
719              $('#CheckBoxArea').append(html);
720              });*/
721         }
722     })
723
724     /* Reference Code -- Remove after use */
725     .controller("coursesCtrl", function($scope, DataService){
726         $scope.message = "Courses Offered";
727         $scope.courses = ["Java", "C/C++", "JavaScript", "AngularJS", "NodeJS", "HTML", "Python", "Action Script"];
728         $scope.showDialog = function() {
729             /*var dialog_tpl = $(modelTemplate).filter('#personDialog').html();
730              var data = {'title':'Shahid Noor','showClose':true,'closeBtnTxt':'Cancel','icon':'glyphicon glyphicon-off','iconColor':'icon_warn','msg':'Good! There is a message that can be used to show on the screen. There is a message that can be used to show on the screen', buttons:[{"text": "Ok", 'action':'callThis()'},{"text": "Show"}]};
731              var html = Mustache.to_html(dialog_tpl, data);
732              $(html).modal({backdrop: "static"});   //backdrop: "static" - for grayed out and no outside click work, backdrop: false - no grayed out*/
733
734             var def_button_tpl = $(modelTemplate).filter('#visualButtons').html();
735             var def_btn_data = {'title':"asas", 'type':'primary'};
736             var html = Mustache.to_html(def_button_tpl, def_btn_data);
737             $('#sampleArea').html(html);
738         };
739
740         // $scope.$on('$viewContentLoaded', function(){
741         function loaded(){
742             console.log("Loaded..");
743             //Here your view content is fully loaded !!
744             var def_button_tpl = $(modelTemplate).filter('#dropDown').html();
745             var def_btn_data = {'title':'Shahid Noor','position':'down', items:[{"itemLabel": "Ok"},{"itemLabel": "Show"}]};
746             var html = Mustache.to_html(def_button_tpl, def_btn_data);
747             $('#sampleArea').html(html);
748
749         }
750         $scope.subIsLoaded  = function() {
751             if(modelTemplate != null) {
752                 console.log("Loading..");
753                 loaded();
754                 return true;
755             }
756             console.log("Not Loaded..");
757             return false;
758         }
759     })
760
761     .controller("toolCtrl", function($scope, DataService, $compile, $log){
762                  $scope.toolTip = "shortNote";
763                 $scope.toolTipContent = "textArea";
764
765             DataService.getAllData($scope.toolTipContent)
766             .then(function(data){
767                 $log.info(data.Note.placement);
768                 $scope.noteContent = data.Note.message;
769                 $scope.notePlacement = data.Note.placement;
770                 $scope.errMsg = data.ErrMsg;
771                 console.log($scope.noteContent + " " + $scope.notePlacement);
772                 loadTextArea();
773             });
774             DataService.getAllData($scope.toolTip)
775                 .then(function(data){
776                     $scope.toolTipData = data.toolTip;
777                     //loadTextArea();
778                 });
779
780         //$('[data-toggle="popover"]').popover();
781
782
783
784         function loadTextArea() {
785             var text = $(modelTemplate).filter('#textfield').html();
786             var email = $(modelTemplate).filter('#email').html();
787             var url = $(modelTemplate).filter('#url').html();
788             var password = $(modelTemplate).filter('#password').html();
789             var numeric = $(modelTemplate).filter('#numeric').html();
790             var dot = $(modelTemplate).filter('#dot').html();
791             var dateinput = $(modelTemplate).filter('#dateinput').html();
792             var monthinput = $(modelTemplate).filter('#monthinput').html();
793             var weekinput = $(modelTemplate).filter('#weekinput').html();
794             var timeinput = $(modelTemplate).filter('#timeinput').html();
795             var ipv4 = $(modelTemplate).filter('#ipv4').html();
796             var ipv6 = $(modelTemplate).filter('#ipv6').html();
797             var textarea = $(modelTemplate).filter('#textarea').html();
798
799             var note = $(modelTemplate).filter('#note').html();
800
801             var dataText = {"errMsg" :     {"textboxErr" : "The name is required.", "modalVar":"province.province_name", "placeholder":""}};
802             var html = Mustache.to_html(text, dataText.errMsg);
803             $('#fname').html($compile(html)($scope));
804
805             var html = Mustache.to_html(email, $scope.errMsg);
806             $('#email').html($compile(html)($scope));
807
808             var html = Mustache.to_html(url, $scope.errMsg);
809             $('#url').html($compile(html)($scope));
810
811             var html = Mustache.to_html(password, $scope.errMsg);
812             $('#password').html($compile(html)($scope));
813
814             var dataNum = {"errMsg" :     {"numericErr" : "The number is required.", "modalVar":"province.port", "placeholder":""}};
815             var html = Mustache.to_html(numeric, dataNum.errMsg);
816             $('#numeric').html($compile(html)($scope));
817
818
819             var html = Mustache.to_html(dot, $scope.errMsg);
820             $('#dot').html($compile(html)($scope));
821
822             var html = Mustache.to_html(dateinput, $scope.errMsg);
823             $('#dateinput').html($compile(html)($scope));
824
825             var html = Mustache.to_html(monthinput, $scope.errMsg);
826             $('#monthinput').html($compile(html)($scope));
827
828             var html = Mustache.to_html(weekinput, $scope.errMsg);
829             $('#weekinput').html($compile(html)($scope));
830
831             var html = Mustache.to_html(timeinput, $scope.errMsg);
832             $('#timeinput').html($compile(html)($scope));
833
834             var dataIP = {"errMsg" :     {"ipv4Err" : "The ipv4 is required.", "modalVar":"province.ip", "placeholder":""}};
835             var html = Mustache.to_html(ipv4, dataIP.errMsg);
836             $('#ipv4').html($compile(html)($scope));
837
838             var html = Mustache.to_html(ipv6, $scope.errMsg);
839             $('#ipv6').html($compile(html)($scope));
840
841             var html = Mustache.to_html(textarea, $scope.errMsg);
842             $('#textarea').html($compile(html)($scope));
843
844
845
846             var html = Mustache.to_html(note, {"placement":$scope.notePlacement});
847             $('#note').html(html);
848             $("#noteanchor").popover({
849                 template: '<div class="popover fade bottom in customPopover"><div class="arrow"></div>'+$scope.noteContent+'</div>'
850             });
851
852             $scope.validatetextbox = function (value){
853                if($scope.textbox) {
854                     $scope.textboxErr = false;
855                 }
856                 else
857                     $scope.textboxErr = true;
858
859             }
860             $scope.validateemail = function (value){
861                 if($scope.email) {
862                     $scope.emailErr = false;
863                 }
864                 else
865                     $scope.emailErr = true;
866
867             }
868             $scope.validateurl = function (value){
869                 if($scope.url) {
870                     $scope.urlErr = false;
871                 }
872                 else
873                     $scope.urlErr = true;
874
875             }
876             $scope.validatepassword = function (value){
877                 if($scope.password) {
878                     $scope.passwordErr = false;
879                 }
880                 else
881                     $scope.passwordErr = true;
882
883             }
884             $scope.validatenumeric = function (value){
885                 if($scope.number) {
886                     $scope.numericErr = false;
887                 }
888                 else
889                     $scope.numericErr = true;
890
891             }
892             $scope.validatedot = function (value){
893                 if($scope.datetime) {
894                     $scope.dotErr = false;
895                 }
896                 else
897                     $scope.dotErr = true;
898
899             }
900             $scope.validatedateinput = function (value){
901                 if($scope.date) {
902                     $scope.dateinputErr = false;
903                 }
904                 else
905                     $scope.dateinputErr = true;
906
907             }
908             $scope.validatemonthinput = function (value){
909                 if($scope.month) {
910                     $scope.monthinputErr = false;
911                 }
912                 else
913                     $scope.monthinputErr = true;
914
915             }
916             $scope.validateweek = function (value){
917                 if($scope.week) {
918                     $scope.weekinputErr = false;
919                 }
920                 else
921                     $scope.weekinputErr = true;
922
923             }
924             $scope.validatetime = function (value){
925                 if($scope.time) {
926                     $scope.timeinputErr = false;
927                 }
928                 else
929                     $scope.timeinputErr = true;
930
931             }
932             $scope.validateipv4 = function (value){
933                 if($scope.ipv4) {
934                     $scope.ipv4Err = false;
935                 }
936                 else
937                     $scope.ipv4Err = true;
938
939             }
940             $scope.validateipv6 = function (value){
941                 if($scope.ipv6) {
942                     $scope.ipv6Err = false;
943                 }
944                 else
945                     $scope.ipv6Err = true;
946
947             }
948
949             $scope.validatetextarea = function (value){
950                 if($scope.textarea) {
951                     $scope.textareaErr = false;
952                 }
953                 else
954                     $scope.textareaErr = true;
955
956             }
957
958
959
960         }
961
962
963     })
964
965
966
967
968
969
970
971     .controller("notificationCtrl", function($scope, DataService){
972         $scope.message = "Notification and Messages";
973         $scope.notificationTip = "shortNote";
974
975         var dialog_tpl;
976         $scope.templateLoaded  = function() {
977             if(modelTemplate != null) {
978                 console.log("Loading..");
979
980                 return true;
981             }
982             console.log("Not Loaded..");
983             return false;
984         }
985         $scope.init = function() {
986             $scope.param="notificationData";
987             $scope.notificationTip="shortNote";
988             DataService.getAllData($scope.param)
989                 .then(function(data){
990                     $scope.notification = data;
991                 });
992             DataService.getAllData($scope.notificationTip)
993                 .then(function(data){
994                     $scope.notificationTipData = data.notificationTip;
995                 });
996         }
997
998         $scope.showError = function() {
999             dialog_tpl = $(modelTemplate).filter('#personDialog').html();
1000             var html = Mustache.to_html(dialog_tpl, $scope.notification.err_data);
1001             $(html).modal({backdrop: "static"});//backdrop: "static" - for grayed out and no outside click work, backdrop: false - no grayed out*!
1002         }
1003
1004         $scope.showWarning = function() {
1005             dialog_tpl = $(modelTemplate).filter('#personDialog').html();
1006             var html = Mustache.to_html(dialog_tpl, $scope.notification.warn_data);
1007             $(html).modal();
1008         }
1009
1010         $scope.showInfo = function() {
1011             dialog_tpl = $(modelTemplate).filter('#personDialog').html();
1012             var html = Mustache.to_html(dialog_tpl, $scope.notification.info_data);
1013             $(html).modal();
1014         }
1015         $scope.showConfirm = function() {
1016             dialog_tpl = $(modelTemplate).filter('#personDialog').html();
1017             var html = Mustache.to_html(dialog_tpl, $scope.notification.confirm_data);
1018             $(html).modal({backdrop: "static"});   //backdrop: "static" - for grayed out and no outside click work, backdrop: false - no grayed out*!/
1019         }
1020
1021     })
1022
1023     .controller("functionalCtrl", function($scope, DataService){
1024         $scope.message = "Functional Flow";
1025
1026         var dialog_tpl;
1027         $scope.templateLoaded  = function() {
1028             if(modelTemplate != null) {
1029                 console.log("Loading..");
1030
1031                 return true;
1032             }
1033             console.log("Not Loaded..");
1034             return false;
1035         }
1036
1037         $scope.init = function() {
1038             $scope.param="functionalData";
1039             $scope.functionalTip="shortNote";
1040             DataService.getAllData($scope.param)
1041                 .then(function(data){
1042                     $scope.functional = data;
1043                 });
1044             DataService.getAllData($scope.functionalTip)
1045                 .then(function(data){
1046                     $scope.functionalTipData = data.functionalTip;
1047                 });
1048         }
1049         $scope.showCreate = function() {
1050             dialog_tpl = $(modelTemplate).filter('#functionalDialog').html();
1051             var html = Mustache.to_html(dialog_tpl, $scope.functional.create_data);
1052             $(html).modal();
1053         }
1054         $scope.showModify = function() {
1055             dialog_tpl = $(modelTemplate).filter('#functionalDialog').html();
1056             var html = Mustache.to_html(dialog_tpl, $scope.functional.modify_data);
1057             $(html).modal();
1058         }
1059         $scope.showDelete = function() {
1060             dialog_tpl = $(modelTemplate).filter('#functionalDialog').html();
1061             var html = Mustache.to_html(dialog_tpl, $scope.functional.delete_data);
1062             $(html).modal();
1063         }
1064         $scope.showWorkflow = function() {
1065             dialog_tpl = $(modelTemplate).filter('#functionalDialog').html();
1066             var html = Mustache.to_html(dialog_tpl, $scope.functional.workflow_data);
1067             $(html).modal();
1068         }
1069     })
1070
1071     .controller("listCtrl", function($scope, $log, DataService){
1072         $scope.message = "List Page";
1073         $scope.listTip = "shortNote";
1074         $scope.init = function() {
1075             console.log("Shahid... ng-init");
1076             $scope.param="list";
1077             DataService.getAllData($scope.param)
1078                 .then(function(data){
1079                     $scope.mainlistItem = data;
1080                 }, function(reason){
1081                     $scope.portfolios = [];
1082
1083                 });
1084
1085             DataService.getAllData($scope.listTip)
1086                 .then(function(data){
1087                     $scope.listTipData = data.listTip;
1088                 });
1089         }
1090         $scope.loadSubMenuPage = function(index) {
1091             $log.info($scope.mainlistItem);
1092             $scope.subMenuListItem = $scope.mainlistItem[index].subMenu;
1093             $scope.subsubMenuListItem = [];
1094         }
1095         $scope.loadSubSubMenuPage = function(index) {
1096             $log.info($scope.subMenuListItem);
1097             console.log("index: "+index);
1098             $scope.subsubMenuListItem = $scope.subMenuListItem[index].subsubMenu;
1099         }
1100     })
1101
1102     .controller("managementCtrl", function($scope, $log, DataService, $state, $compile, NgTableParams){
1103         $scope.message = "Management";
1104         $scope.provinceTip = "shortNote";
1105         /*$scope.provinceData = [
1106             {id:1, province_name:'First', ip:'192.168.1.45', port:'8080'},
1107             {id:2, province_name:'Second', ip:'192.168.1.5', port:'8081'},
1108             {id:3, province_name:'Third', ip:'192.168.1.15', port:'8082'},
1109             {id:4, province_name:'Fourth', ip:'192.168.1.28', port:'8083'},
1110             {id:5, province_name:'Fifth', ip:'192.168.1.19', port:'8084'}
1111         ];*/
1112
1113         $scope.init = function() {
1114             console.log("Shahid... ng-init");
1115             DataService.getAllProvinceData()
1116                 .then(function(data){
1117                     $scope.provinceData = data.provinceData;
1118                     console.log("Data: ");
1119                     loadButtons();
1120                     $log.info(data.provinceData);
1121                 }, function(reason){
1122                     $scope.message = "Error is :" + JSON.stringify(reason);
1123                 });
1124
1125             DataService.getAllData($scope.provinceTip)
1126                 .then(function(data){
1127                     $scope.provinceTipData = data.provinceTip;
1128                 });
1129         }
1130
1131         /*DataService.getAllProvinceData()
1132             .then(function(data){
1133                 $scope.provinceData = data.provinceData;
1134                 console.log("Data: ");
1135                 $log.info(data.provinceData);
1136             }, function(reason){
1137                 $scope.message = "Error is :" + JSON.stringify(reason);
1138             });*/
1139         /*DataService.getAllData($scope.provinceTip)
1140             .then(function(data){
1141                 $scope.provinceTipData = data.provinceTip;
1142             });*/
1143
1144         function loadButtons() {
1145             var def_button_tpl = $(modelTemplate).filter('#defaultButtons').html();
1146             var add_data = {"title":"Add", "clickAction":"showAddModal()"};
1147             var delete_data = {"title":"Delete Selected", "clickAction":"deleteData()"};
1148             var addhtml = Mustache.to_html(def_button_tpl, add_data);
1149             var deletehtml = Mustache.to_html(def_button_tpl, delete_data);
1150             $('#provinceAction').html($compile(addhtml)($scope));
1151             $('#provinceAction').append($compile(deletehtml)($scope));
1152
1153             $scope.checkboxes = { 'checked': false, items: {} };
1154
1155             //var data = [{id: 1, name: "Moroni", age: 50}, {id: 2, name: "ABC", age: 30}, {id: 3, name: "Morhoni", age: 10}, {id: 4, name: "DABC", age: 31}, {id: 5, name: "Noor", age: 30}, {id: 6, name: "ABCD", age: 40}, {id: 7, name: "DABC", age: 31}, {id: 8, name: "Noor", age: 30}, {id: 9, name: "ABCD", age: 40}, {id: 10, name: "DABC", age: 31}, {id: 11, name: "Noor", age: 30}, {id: 12, name: "ABCD", age: 40}];
1156             $scope.tableParams = new NgTableParams({count: 5, sorting: {province_name: 'asc'}    //{page: 1,count: 10,filter: {name: 'M'},sorting: {name: 'desc'}
1157             }, { counts:[5, 10, 20, 50], dataset: $scope.provinceData});
1158
1159             $scope.$watch('checkboxes.checked', function(value) {
1160                 angular.forEach($scope.provinceData, function(item) {
1161                     if (angular.isDefined(item.id)) {
1162                         $scope.checkboxes.items[item.id] = value;
1163                     }
1164                 });
1165             });
1166
1167             var text = $(modelTemplate).filter('#textfield').html();
1168             var ipv4 = $(modelTemplate).filter('#ipv4').html();
1169             var number = $(modelTemplate).filter('#numeric').html();
1170
1171             var dataText = {"ErrMsg" :     {"textboxErr" : "The name is required.", "modalVar":"province.province_name", "placeholder":"Name"}};
1172             $('#myModal .provinceName').html($compile(Mustache.to_html(text, dataText.ErrMsg))($scope));
1173
1174             var dataIP = {"ErrMsg" :     {"ipv4Err" : "The ipv4 is required.", "modalVar":"province.ip", "placeholder":"IP Address"}};
1175             $('#myModal .ipAddress').html($compile(Mustache.to_html(ipv4, dataIP.ErrMsg))($scope));
1176
1177             var dataNum = {"ErrMsg" :     {"numericErr" : "The number is required.", "modalVar":"province.port", "placeholder":"Port"}};
1178             $('#myModal .port').html($compile(Mustache.to_html(number, dataNum.ErrMsg))($scope));
1179
1180             var modelSubmit_data = {"title":"Submit", "clickAction":"saveData(province.id)"};
1181             var modelSubmit_html = Mustache.to_html(def_button_tpl, modelSubmit_data);
1182             $('#myModal #footerBtns').html($compile(modelSubmit_html)($scope));
1183
1184             var modelDelete_data = {"title":"Close", "clickAction":"closeModal()"};
1185             var modelDelete_html = Mustache.to_html(def_button_tpl, modelDelete_data);
1186             $('#myModal #footerBtns').append($compile(modelDelete_html)($scope));
1187         }
1188
1189         $scope.validatetextbox = function (value){
1190             if($scope.province.province_name) {
1191                 $scope.textboxErr = false;
1192             }
1193             else
1194                 $scope.textboxErr = true;
1195         }
1196         $scope.validateipv4 = function (value){
1197             if($scope.province.ip) {
1198                 $scope.ipv4Err = false;
1199             }
1200             else
1201                 $scope.ipv4Err = true;
1202         }
1203         $scope.validatenumeric = function (value){
1204             if($scope.province.port) {
1205                 $scope.numericErr = false;
1206             }
1207             else
1208                 $scope.numericErr = true;
1209         }
1210
1211         $scope.closeModal = function() {
1212             console.log("Closing Modal...");
1213             $('#myModal').modal('hide');
1214         }
1215
1216
1217         $scope.checkAll = function() {
1218             console.log("Checked ..");
1219             angular.forEach($scope.provinceData, function(data) {
1220                 //data.select = $scope.selectAll;
1221                 $scope.checkboxes.items[user.id]
1222             });
1223         };
1224
1225         $scope.showAddModal = function() {
1226             console.log("Showing Modal to Add data");
1227             $scope.province = {};
1228             $scope.textboxErr = false;
1229             $scope.ipv4Err = false;
1230             $scope.numericErr = false;
1231             $("#myModal").modal();
1232         }
1233         $scope.saveData = function(id) {
1234             if(id) {
1235                 //edit data
1236                 console.log("Editing data.." + JSON.stringify($scope.province));
1237                 DataService.editProvinceData($scope.province)
1238                     .then(function (data) {
1239                             $scope.message = "Success :-)";
1240                             $state.reload();
1241                             //$state.go($state.current.name, {}, {reload: true})
1242                         },
1243                         function (reason) {
1244                             //$log.info(reason);
1245                             $scope.message = reason.status + " " + reason.statusText;
1246                         });
1247             }
1248             else {
1249                 console.log("Adding data.." + JSON.stringify($scope.province));
1250                 DataService.addProvinceData($scope.province)
1251                     .then(function (data) {
1252                             $scope.message = "Success :-)";
1253                             $state.reload();
1254                             //$state.go($state.current.name, {}, {reload: true})
1255                         },
1256                         function (reason) {
1257                             //$log.info(reason);
1258                             $scope.message = reason.status + " " + reason.statusText;
1259                         });
1260             }
1261             $('#myModal').modal('hide');
1262         }
1263
1264         $scope.deleteData = function() {
1265             var deleteArr = [];
1266             //$log.info($scope.checkboxes);
1267             angular.forEach($scope.checkboxes.items, function(value , key) {
1268                 //$log.info(data);
1269                 if(value) {
1270                     deleteArr.push(key);
1271                 }
1272             });
1273
1274             console.log("To be deleted : "+deleteArr);
1275             //$log.info(deleteArr);
1276             DataService.deleteProvinceData(deleteArr)
1277                 .then(function(data){
1278                         $scope.message = "Successfully deleted :-)";
1279                         $state.reload();
1280                     },
1281                     function(reason){
1282                         //$log.info(reason);
1283                         $scope.message = reason.status + " " + reason.statusText;
1284                     });
1285         }
1286
1287         $scope.deleteIndividualData = function(id) {
1288             var deleteArr = [];
1289             //$log.info($scope.checkboxes);
1290             deleteArr.push(id);
1291
1292             console.log("To be deleted : "+deleteArr);
1293             //$log.info(deleteArr);
1294             DataService.deleteProvinceData(deleteArr)
1295                 .then(function(data){
1296                         $scope.message = "Successfully deleted :-)";
1297                         $state.reload();
1298                     },
1299                     function(reason){
1300                         //$log.info(reason);
1301                         $scope.message = reason.status + " " + reason.statusText;
1302                     });
1303         }
1304
1305         $scope.editData = function(id) {
1306             $scope.textboxErr = false;
1307             $scope.ipv4Err = false;
1308             $scope.numericErr = false;
1309             console.log("To be edited : " + id);
1310             var dataFound = false;
1311             angular.forEach($scope.provinceData, function(data) {
1312                 if(!dataFound) {
1313                     if (data.id == id) {
1314                         console.log("Found : " + data.id);
1315                         $scope.province = data;
1316                         /*$scope.province.province_name = data.province_name;
1317                         $scope.province.ip = data.ip;
1318                         $scope.province.port = data.port;*/
1319
1320                         $("#myModal").modal();
1321                         dataFound = true;
1322                     }
1323                 }
1324             });
1325         }
1326
1327     })
1328
1329 var modelTemplate;
1330 function loadTemplate() {
1331     $.get('template.html', function(template) {
1332         modelTemplate = template;
1333     });
1334 }
1335
1336 function callThis() {
1337     alert("Going Great!");
1338 }
1339
1340 function searchTable() {
1341     var filter, table, tr, td;
1342     filter = $("#myInput").val().toUpperCase();
1343     table = $("#myTable_search");
1344     tr = $("#myTable_search tr");
1345
1346     // Loop through all table rows, and hide those who don't match the search query
1347     for (var i = 0; i < tr.length; i++) {
1348         td = tr[i].getElementsByTagName("td")[0];
1349         if (td) {
1350             if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
1351                 tr[i].style.display = "";
1352             } else {
1353                 tr[i].style.display = "none";
1354             }
1355         }
1356     }
1357 }
1358
1359 function linkClicked(state) {
1360     console.log("State to : " + state);
1361 }