LDAP_search using $resource
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 10 Jul 2011 13:33:21 +0000 (15:33 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 10 Jul 2011 13:33:21 +0000 (15:33 +0200)
public/user.html

index 96d44cc..1f4f071 100644 (file)
@@ -7,11 +7,13 @@
        var self = this;
    
        self.r = {
        var self = this;
    
        self.r = {
-               CRM_search: $resource('/g/CRM_search/:username', {username:'@search_username'}),
+               CRM_search:  $resource('/g/CRM_search/:username', {username:'@search_username'}),
+               LDAP_search: $resource('/g/LDAP_search/:username', {username:'@selected_username'}),
        };
        self.CRM_search = function(username) {
                if ( ! username ) username = self.search_username;
                $log.info( 'CRM_search', username );
        };
        self.CRM_search = function(username) {
                if ( ! username ) username = self.search_username;
                $log.info( 'CRM_search', username );
+               self.clear();
                self.r.CRM_search.query({username: username}, function(CRM) {
                        self.CRM = CRM;
                        $log.info( 'CRM', CRM )
                self.r.CRM_search.query({username: username}, function(CRM) {
                        self.CRM = CRM;
                        $log.info( 'CRM', CRM )
                        }
                });
        };
                        }
                });
        };
+
+       self.LDAP_search = function(username) {
+               if ( ! username ) username = self.selected_username;
+               if ( ! username ) {
+                       $log.error( 'no username for LDAP_search' );
+                       return;
+               }
+               $log.info( 'LDAP_search', username );
+               self.r.LDAP_search.query({ username: username }, function(LDAP) {
+                       self.LDAP = LDAP;
+                       $log.info( 'LDAP', LDAP );
+                       self.username = LDAP[0].cn;
+                       self.cpe = {
+                               parser: LDAP[0]._cpe_parser,
+                               table: 'cpe_' + LDAP[0]._cpe_parser,
+                       };
+               });
+       };
+       self.$watch('selected_username', self.LDAP_search );
  
       this.clear = function() {
  
       this.clear = function() {
-        self.url = null;
-        self.code = null;
+       self.CRM = null;
+       self.LDAP = null;
        self.selected_username = null;
        self.gnuplot = {};
        self.ldap = null;
        self.selected_username = null;
        self.gnuplot = {};
        self.ldap = null;
@@ -192,8 +213,8 @@ th, td {
 
     <h2><tt>{{selected_username}}</tt> LDAP entry</h2>
 
 
     <h2><tt>{{selected_username}}</tt> LDAP entry</h2>
 
-    <ul ng:show="ldap">
-    <li ng:repeat="c in keys(ldap)"><tt>{{c}}</tt> {{ldap[0][c]}}</li>
+    <ul ng:show="LDAP">
+    <li ng:repeat="c in keys(LDAP)"><tt>{{c}}</tt> {{LDAP[0][c]}}</li>
     </ul>
 
     <div ng:show="cpe.rows">
     </ul>
 
     <div ng:show="cpe.rows">
@@ -208,7 +229,7 @@ th, td {
     <input type=checkbox name=debug value=1>
     <pre ng:show=debug>
 CRM={{CRM}}
     <input type=checkbox name=debug value=1>
     <pre ng:show=debug>
 CRM={{CRM}}
-ldap={{ldap}}
+LDAP={{LDAP}}
 cpe={{cpe}}
 gnuplot={{gnuplot}}
     </pre>
 cpe={{cpe}}
 gnuplot={{gnuplot}}
     </pre>