select row from CRM results by clicking on it
[APKPM.git] / templates / user.html.ep
1 % layout 'angular';
2
3   <script>
4     function CRM($xhr) {
5       var self = this;
6    
7       this.fetch = function() {
8         self.clear();
9         self.url = '/g/' + self.function_name + '/' + self.args + '?callback=JSON_CALLBACK';
10         $xhr('JSON', self.url, function(code, response) {
11           self.code = code;
12           self.response = response;
13         });
14       };
15    
16       this.clear = function() {
17         self.url = null;
18         self.code = null;
19         self.response = null;
20       };
21
22         this.columns = [
23                 'USERNAME',
24                 'BROJ',
25                 'USLUGA',
26                 'IP_MANAGEMENT',
27                 'IP_VOICE',
28                 'KOLOKACIJA',
29                 'OPT82'
30         ];
31
32       this.keys = function(h) {
33              if ( angular.isArray(h) ) h = h[0];
34              var keys = [];
35              for(i in h) if (h.hasOwnProperty(i))
36              {
37                keys.push(i);
38              }
39              return keys;
40       };
41
42         this.select = function(crm) {
43                 console.log( crm );
44                 self.selected_username = crm.USERNAME;
45         };
46
47         this.selected_username = '';
48
49     }
50
51     CRM.$inject = ['$xhr'];
52   </script>
53   <div ng:controller="CRM">
54     <input type="hidden" name="function_name" value="CRM_search"      size="20"/>
55     <label for="args">username:
56     <input type="text" name="args"     value="test" size="10"/>
57     </label>
58     <button ng:click="fetch()">fetch</button>
59     <button ng:click="clear()">clear</button>
60     <b ng:show="url && ! code">loading {{url}}</b>
61     <b ng:show="response">{{response.length}} results</b>
62
63 <div style="font-size: 80%; float: right" ng:show="response">
64 Add columns:
65 <ul>
66 <li ng:repeat="c in keys(response)" ng:show="columns.indexOf(c) < 0" ng:click="columns.push(c)">{{c}}
67 </ul>
68 </div>
69
70     <table ng:show="response">
71     <tr>
72         <th ng:repeat="c in columns" ng:click="columns.$remove(c)">{{c}}</th>
73     </tr>
74     <tr ng:repeat="u in response" ng:click="select(u)">
75         <td ng:repeat="c in columns" ng:show="! selected_username || selected_username == u.USERNAME">{{u[c]}}</td>
76     </tr>
77     </table>
78
79     <input type=button value="Show ALL results, not just {{selected_username}}" ng:click="selected_username=''" ng:show="selected_username">
80
81     <input type=checkbox name=debug value=1>
82     <pre ng:show=debug>
83 url={{url}}
84 code={{code}}
85 response={{response}}
86 username={{username}}
87     </pre>
88   </div>