couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [04/13] git commit: updated refs/heads/master to 0cd82b9
Date Wed, 15 May 2013 08:29:04 GMT
basic create admin role and admin party


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/44056da4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/44056da4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/44056da4

Branch: refs/heads/master
Commit: 44056da4ccf0bb2d9fa50a5ba6e6650e75199a78
Parents: 545ef1f
Author: Garren Smith <garren.smith@gmail.com>
Authored: Fri Mar 22 15:00:40 2013 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Wed May 15 10:20:39 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/addons/user/base.js      |    4 +-
 src/fauxton/app/addons/user/resources.js |  105 +++++++++++++++++++++----
 src/fauxton/app/addons/user/routes.js    |   21 +++++
 src/fauxton/settings.json.default        |    3 +-
 4 files changed, 114 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/44056da4/src/fauxton/app/addons/user/base.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/user/base.js b/src/fauxton/app/addons/user/base.js
index fd9d9c6..d1c9334 100644
--- a/src/fauxton/app/addons/user/base.js
+++ b/src/fauxton/app/addons/user/base.js
@@ -13,13 +13,13 @@
 define([
        "app",
        "api",
-       "addons/user/resources"
+       "addons/user/routes"
 ],
 
 function(app, FauxtonAPI, User) {
 
   User.initialize = function() {
-    FauxtonAPI.addHeaderLink({title: "User", href: "#user"});
+    FauxtonAPI.addHeaderLink({title: "User", href: "#_user"});
   };
 
   return User;

http://git-wip-us.apache.org/repos/asf/couchdb/blob/44056da4/src/fauxton/app/addons/user/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/user/resources.js b/src/fauxton/app/addons/user/resources.js
index 1410164..f6bd180 100644
--- a/src/fauxton/app/addons/user/resources.js
+++ b/src/fauxton/app/addons/user/resources.js
@@ -1,38 +1,111 @@
 define([
        "app",
-       "api"
+       "api",
+       "addons/config/resources"
 ],
 
-function (app, FauxtonAPI) {
+function (app, FauxtonAPI, Config) {
   var User = new FauxtonAPI.addon();
 
   User.Session = Backbone.Model.extend({
     url: '/_session',
+
+    is_admin_party: function () {
+      var userCtx = this.get('userCtx');
+      if (!userCtx.name && userCtx.roles.indexOf("_admin") !== -1) {
+        return true;
+      }
+
+      return false;
+    },
+
+    create_admin: function (username, password) {
+      if (_.isEmpty(username) || _.isEmpty(password)) {
+        var deferred = $.Deferred();
+        
+        deferred.reject('Username or password cannot be blank.');
+        return deferred;
+      }
+
+      var admin = new Config.OptionModel({
+        section: "admins",
+        name: username,
+        value: password
+      });
+      return admin.save();
+    }
+  });
+
+  User.CreateAdminModal = FauxtonAPI.View.extend({
+    template: 'addons/user/templates/create_admin_modal',
+
+    events: {
+      "click #create-admin": "create_admin"
+    },
+
+    create_admin: function (event) {
+      event.preventDefault();
+      var self = this,
+          username = this.$('#username').val(),
+          password = this.$('#password').val();
+
+      var promise = this.model.create_admin(username, password);
+
+      promise.done(function () {
+        self.$('.modal').modal('hide');
+        self.trigger('admin_created');
+      });
+
+      promise.fail(function (msg) {
+        self.$('#modal-error').text(msg).removeClass('hide');
+      });
+    },
+
+    show_modal: function () {
+      this.$('.modal').modal();
+    }
   });
-  
+
   User.Info = FauxtonAPI.View.extend({
+    template: 'addons/user/templates/info',
 
     initialize:function (options) {
       this.model.on('change', this.update_session, this);
     },
 
-    update_session: function () {
-      console.log('update session');
-      console.log(this.model);
-    }
-  });
+    serialize: function () {
+      return {
+        admin_party: this.model.is_admin_party()
+      };
+    },
+
+    events: {
+      "click #user-create-admin": 'show_admin_modal'
+    },
 
-  var session = new User.Session();
+    beforeRender: function () {
+      this.create_admin_modal = this.setView('#user-create-admin-modal', new  User.CreateAdminModal({model:
this.model}));
+      this.create_admin_modal.on('admin_created', this.render);
+    },
+
+    afterRender: function () {
+      if (this.model.is_admin_party()) {
+        console.log('admin party');
+        return;
+      } else {
+        console.log('not admin');
+      }
+    },
+
+    show_admin_modal: function (event) {
+      event.preventDefault();
+      this.create_admin_modal.show_modal();
+    },
 
-  User.Layout = Backbone.Layout.extend({
-    views: {
-      'a[href="#user"]': new User.Info({model: session})
+    update_session: function () {
+      console.log(this.model);
     }
   });
 
-  var layout = new User.Layout();
-
-  layout.render();
-  session.fetch();
   return User;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/44056da4/src/fauxton/app/addons/user/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/user/routes.js b/src/fauxton/app/addons/user/routes.js
index 010ab24..9108072 100644
--- a/src/fauxton/app/addons/user/routes.js
+++ b/src/fauxton/app/addons/user/routes.js
@@ -5,5 +5,26 @@ define([
 ],
 
 function(app, FauxtonAPI, User) {
+
+  var userRoutes = function () {
+
+    var session = new User.Session();
+    return {
+      layout: 'one_pane',
+      crumbs: [{"name": "User","link": "_user"}],
+      views: {
+        "#dashboard-content": new User.Info({model: session})
+      },
+      establish: function () {
+        return [session.fetch()];
+      },
+      apiUrl: 'boom'
+    };
+  };
+
+  User.Routes = {
+    "_user": userRoutes
+  };
+
   return User;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/44056da4/src/fauxton/settings.json.default
----------------------------------------------------------------------
diff --git a/src/fauxton/settings.json.default b/src/fauxton/settings.json.default
index b4c0dbc..ef986ba 100644
--- a/src/fauxton/settings.json.default
+++ b/src/fauxton/settings.json.default
@@ -3,7 +3,8 @@
   { "name": "config" },
   { "name": "logs" },
   { "name": "stats" },
-  { "name": "contribute" }
+  { "name": "contribute" },
+  { "name": "user" }
   ],
     "template": {
       "src": "assets/index.underscore",


Mime
View raw message