]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
More users thingy
authorpho <pho@cielonegro.org>
Fri, 1 Aug 2008 09:18:01 +0000 (18:18 +0900)
committerpho <pho@cielonegro.org>
Fri, 1 Aug 2008 09:18:01 +0000 (18:18 +0900)
darcs-hash:20080801091801-62b54-f601f90bf662aeb4061cb7625a0a2fd7fec4fda0.gz

Rakka/Resource/Users.hs
js/Makefile
js/jquery-dom.js
js/systemConfig.js

index 7eb0e136b0974dbc4121825cdb664e1c0084dc04..a4bf60204b047d54944afb08dadc62fd08386f13 100644 (file)
@@ -7,12 +7,9 @@ import           Control.Monad
 import           Control.Monad.Trans
 import           Data.Maybe
 import           Network.HTTP.Lucu
-import           Network.URI hiding (path)
 import           Rakka.Authorization
 import           Rakka.Environment
 import           Rakka.Resource
-import           Rakka.SystemConfig
-import           System.FilePath
 import           Text.XML.HXT.Arrow hiding (when)
 
 
@@ -31,17 +28,11 @@ resUsers env
 
 {-
   [GET /users]
-  <rdf:RDF>
-    <rdf:Description rdf:about="http://.../users">
-      <users>
-        <rdf:Bag>
-          <rdf:li rdf:resource="http://.../users/foo" />
-         <rdf:li rdf:resource="http://.../users/bar" />
-         ...
-       </rdf:Bag>
-      </users>
-    </rdf:Description>
-  </rdf:RDF>
+  <users>
+    <user id="foo" />
+    <user id="bar" />
+    ...
+  </users>
 
   [GET /users/foo]
   204 No Content
@@ -63,42 +54,20 @@ handleGet env
     where
     returnUserList :: Resource ()
     returnUserList
-       = do BaseURI baseURI <- getSysConf (envSysConf env)
-            users           <- liftIO $ getUserList $ envAuthDB env
+       = do users <- liftIO $ getUserList $ envAuthDB env
             runIdempotentA' $ proc ()
                 -> do tree <- ( eelem "/"
-                                += ( eelem "rdf:RDF"
-                                     += sattr "xmlns"     "http://cielonegro.org/terms/"
-                                     += sattr "xmlns:rdf" "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-                                     += ( eelem "rdf:Description"
-                                          += sattr "rdf:about" (uriToString id (mkUserURI baseURI Nothing) "")
-                                          += ( eelem "users"
-                                               += ( eelem "rdf:Bag"
-                                                    += ( constL users
-                                                         >>>
-                                                         ( eelem "rdf:li"
-                                                           += attr "rdf:resource" ( arr ( \ name ->
-                                                                                          uriToString
-                                                                                          id
-                                                                                          (mkUserURI baseURI $ Just name)
-                                                                                          ""
-                                                                                        )
-                                                                                    >>>
-                                                                                    mkText
-                                                                                  )
-                                                         )
-                                                       )
-                                                  )
-                                             )
+                                += ( eelem "users"
+                                     += ( constL users
+                                          >>>
+                                          ( eelem "user"
+                                            += attr "id" mkText
+                                          )
                                         )
                                    )
                               ) -< ()
                       returnA -< outputXml tree
 
-    mkUserURI :: URI -> Maybe String -> URI
-    mkUserURI baseURI Nothing  = baseURI { uriPath = uriPath baseURI </> "users" }
-    mkUserURI baseURI (Just x) = baseURI { uriPath = uriPath baseURI </> "users" </> x }
-
     returnUser :: String -> Resource ()
     returnUser name
        = do users <- liftIO $ getUserList $ envAuthDB env
index e1e6b0cd3fa1c310315a71faddb1994dab80aba6..891e9eb62a1601819caa4e64c01988726cc13ae2 100644 (file)
@@ -36,7 +36,7 @@ clean:
        rm -f ../Rakka/Resource/JavaScript.hs packed.js $(JQUERY_PACKED)
 
 
-yuicompressor.jar:
-       @echo "Error: yuicompressor.jar has to be placed on this directory."
+$(COMPRESSOR):
+       @echo "Error: $(COMPRESSOR) has to be placed on this directory."
        @echo "       See http://www.julienlecomte.net/yuicompressor/"
        @exit 1
index 01270175ac88f34f0c586efa01a49485a8c040a8..70b07e84c2c4f4c1fe1422ca510b063d89b31d2e 100644 (file)
@@ -26,7 +26,7 @@ $.NBSP = '\u00a0';
 $._createNode = function( tag, args ) {
        var fix = { 'class':'className', 'Class':'className' };
        var e;
-       try {
+       //try {
                var attrs = args[0] || {};
                e = document.createElement( tag );
                for( var attr in attrs ) {
@@ -40,13 +40,13 @@ $._createNode = function( tag, args ) {
                        else for( var j = 0;  j < arg.length;  j++ )
                                append( arg[j] );
                }
-       }
-       catch( ex ) {
-               alert( 'Cannot create <' + tag + '> element:\n' +
-                       args.toSource() + '\n' + args );
-               e = null;
-       }
-       
+       //}
+       //catch( ex ) {
+               //alert( 'Cannot create <' + tag + '> element:\n' +
+               //      args.toSource() + '\n' + args );
+               //e = null;
+       //}
+
        function append( arg ) {
                if( arg == null ) return;
                var c = arg.constructor;
@@ -56,6 +56,6 @@ $._createNode = function( tag, args ) {
                }
                e.appendChild( arg );
        }
-       
+
        return e;
 };
index 5fc8303611cbb2df46c144bcbd9333228327759f..16002bb7e78947d5a9ebaa5d0b7ce9357210cb96 100644 (file)
 (function () {
 
-     var identityDecoder = function (src) {
-         return src;
-     };
+    var identityDecoder = function (src) {
+        return src;
+    };
 
-     var identityEncoder = function (src) {
-         return src;
-     };
+    var identityEncoder = function (src) {
+        return src;
+    };
 
-     var mapDecoder = function (src) {
-         var map   = {};
-         var lines = src.split(/\n/);
+    var mapDecoder = function (src) {
+        var map   = {};
+        var lines = src.split(/\n/);
 
-         $.each(lines, function () {
-                    var m = this.match(/^(\S+)\s+(\S+)$/);
+        $.each(lines, function () {
+                  var m = this.match(/^(\S+)\s+(\S+)$/);
 
-                    map[ m[1] ] = m[2];
-                });
+                   map[ m[1] ] = m[2];
+               });
 
-         return map;
-     };
+        return map;
+    };
 
-     var mapEncoder = function (map) {
-         var lines = [];
+    var mapEncoder = function (map) {
+        var lines = [];
 
-         $.each(map, function (key) {
-                    lines.push(key + " " + this);
-                });
+        $.each(map, function (key) {
+                   lines.push(key + " " + this);
+               });
 
-         return lines.join("\n");
-     };
+        return lines.join("\n");
+    };
 
-     var boolDecoder = function (src) {
-         return src == "*";
-     };
+    var boolDecoder = function (src) {
+        return src == "*";
+    };
 
-     var boolEncoder = function (bool) {
-         return bool ? "*" : "";
-     };
+    var boolEncoder = function (bool) {
+        return bool ? "*" : "";
+    };
 
-     var decoder_of = {
-         siteName   : identityDecoder,
-         baseURI    : identityDecoder,
-         defaultPage: identityDecoder,
-         styleSheet : identityDecoder,
-         languages  : mapDecoder,
-         globalLock : boolDecoder
-     };
+    var decoder_of = {
+        siteName   : identityDecoder,
+        baseURI    : identityDecoder,
+        defaultPage: identityDecoder,
+        styleSheet : identityDecoder,
+        languages  : mapDecoder,
+        globalLock : boolDecoder
+    };
 
-     var encoder_of = {
-         siteName   : identityEncoder,
-         baseURI    : identityEncoder,
-         defaultPage: identityEncoder,
-         styleSheet : identityEncoder,
-         languages  : mapEncoder,
-         globalLock : boolEncoder
-     };
+    var encoder_of = {
+        siteName   : identityEncoder,
+        baseURI    : identityEncoder,
+        defaultPage: identityEncoder,
+        styleSheet : identityEncoder,
+        languages  : mapEncoder,
+        globalLock : boolEncoder
+    };
 
-     var cachedConf = null;
+    var cachedConf = null;
 
-     var isValidBaseURI = function (str) {
-         parseUri.options.strictMode = true;
-         var uri = parseUri(str);
+    var isValidBaseURI = function (str) {
+        parseUri.options.strictMode = true;
+        var uri = parseUri(str);
 
-         return (uri.protocol != "" &&
-                 uri.authority != "" &&
-                 uri.path != "" &&
-                 uri.path.match(/\/$/) &&
-                 uri.query == "" &&
-                 uri.anchor == "");
-     };
+        return (uri.protocol != "" &&
+                uri.authority != "" &&
+                uri.path != "" &&
+                uri.path.match(/\/$/) &&
+                uri.query == "" &&
+                uri.anchor == "");
+    };
 
-     var isValidMap = function (src) {
-        return src.match(/^\S+\s+\S+(?:\n\S+\s+\S+)*\n?$/) != null;
-     };
+    var isValidMap = function (src) {
+       return src.match(/^\S+\s+\S+(?:\n\S+\s+\S+)*\n?$/) != null;
+    };
+
+    Rakka.getUserList = function () {
+       var users = [];
+
+       $.ajax({
+                  type: "GET",
+                  url: Rakka.baseURI + "users",
+                  async: false,
+                  beforeSend: function (req) {
+                      Rakka.setAuthorization(req);
+                  },
+                  success: function (xml) {
+                      $(xml).find("user").each(function () {
+                          users.push(this.getAttribute("id"));
+                      });
+                  },
+                  error: function (req) {
+                      throw new Error(req.status + " " + req.statusText);
+                  }
+       });
+
+       return users;
+    };
 
     Rakka.getSystemConfig = function () {
         if (cachedConf != null) {
         return conf;
     };
 
-     Rakka.showConfigPanel = function () {
-         var conf  = Rakka.getSystemConfig();
-         var $area = Rakka.switchScreen();
-
-         $area.append($.H1({}, "Configuration"));
+    var appendConfigPanel = function ($area) {
+       var conf  = Rakka.getSystemConfig();
+       $area.append($.H1({}, "Configuration"));
 
          var fldSiteName
              = $.INPUT({type: "text", value: conf.siteName});
          $area.append(configPanel);
      };
 
-    $(document).ready(function () {
-        $("input.configButton")
-            .click(function () {
-                       Rakka.showConfigPanel();
-                   });
-    });
+     var appendUsersPanel = function ($area) {
+        $area.append($.H2({}, "Users"));
+        $area.append($.H3({}, "Existing Users"));
+
+        var tbody = $.TBODY();
+
+        var usersPanel
+            = $.TABLE({className: "pageEditor"},
+                      $.THEAD({},
+                              $.TR({},
+                                   $.TH({}, "User ID"),
+                                   $.TH({}, "Change Password"),
+                                   $.TH({}, "Delete User")
+                                  )
+                             ),
+                      tbody
+                     );
+
+        var updateUserList = function () {
+            var users = Rakka.getUserList();
+
+            $(tbody).empty();
+
+            $.each(users, function () {
+                       var id = this;
+                       var tr = $.TR({},
+                                     $.TD({}, id),
+                                     $.TD({}, ""),
+                                     $.TD({}, "")
+                                    );
+                       tbody.appendChild(tr);
+                   });
+        };
+        updateUserList();
+
+        $area.append(usersPanel);
+     };
+
+     Rakka.showConfigPanel = function () {
+        var $area = Rakka.switchScreen();
+
+       appendConfigPanel($area);
+       appendUsersPanel($area);
+     };
 
+     $(document).ready(function () {
+                          $("input.configButton")
+                              .click(function () {
+                                         Rakka.showConfigPanel();
+                                     });
+                      });
 })();
\ No newline at end of file