summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2013-04-02 10:27:07 +0200
committerGarren Smith <garren.smith@gmail.com>2013-05-15 10:20:39 +0200
commit6645b566eb2e2d357d7d4e0d06651ef9d9388aef (patch)
tree5578767a1ae19f55f252378d8ba6f2675d0abf15
parent44056da4ccf0bb2d9fa50a5ba6e6650e75199a78 (diff)
downloadcouchdb-6645b566eb2e2d357d7d4e0d06651ef9d9388aef.tar.gz
rename to auth module
-rw-r--r--src/fauxton/app/addons/user/base.js26
-rw-r--r--src/fauxton/app/addons/user/resources.js111
-rw-r--r--src/fauxton/app/addons/user/routes.js30
-rw-r--r--src/fauxton/app/modules/fauxton/base.js11
-rw-r--r--src/fauxton/app/templates/fauxton/nav_bar.html4
-rw-r--r--src/fauxton/settings.json.default2
6 files changed, 15 insertions, 169 deletions
diff --git a/src/fauxton/app/addons/user/base.js b/src/fauxton/app/addons/user/base.js
deleted file mode 100644
index d1c9334dd..000000000
--- a/src/fauxton/app/addons/user/base.js
+++ /dev/null
@@ -1,26 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-define([
- "app",
- "api",
- "addons/user/routes"
-],
-
-function(app, FauxtonAPI, User) {
-
- User.initialize = function() {
- FauxtonAPI.addHeaderLink({title: "User", href: "#_user"});
- };
-
- return User;
-});
diff --git a/src/fauxton/app/addons/user/resources.js b/src/fauxton/app/addons/user/resources.js
deleted file mode 100644
index f6bd18075..000000000
--- a/src/fauxton/app/addons/user/resources.js
+++ /dev/null
@@ -1,111 +0,0 @@
-define([
- "app",
- "api",
- "addons/config/resources"
-],
-
-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);
- },
-
- serialize: function () {
- return {
- admin_party: this.model.is_admin_party()
- };
- },
-
- events: {
- "click #user-create-admin": 'show_admin_modal'
- },
-
- 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();
- },
-
- update_session: function () {
- console.log(this.model);
- }
- });
-
- return User;
-});
diff --git a/src/fauxton/app/addons/user/routes.js b/src/fauxton/app/addons/user/routes.js
deleted file mode 100644
index 9108072d2..000000000
--- a/src/fauxton/app/addons/user/routes.js
+++ /dev/null
@@ -1,30 +0,0 @@
-define([
- "app",
- "api",
- "addons/user/resources"
-],
-
-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;
-});
diff --git a/src/fauxton/app/modules/fauxton/base.js b/src/fauxton/app/modules/fauxton/base.js
index 2526f8038..43cb815bc 100644
--- a/src/fauxton/app/modules/fauxton/base.js
+++ b/src/fauxton/app/modules/fauxton/base.js
@@ -67,7 +67,18 @@ function(app, Backbone) {
this.navLinks.push(link);
}
this.trigger("link:add");
+
this.render();
+ },
+
+ afterRender: function () {
+ _.each(this.navLinks, function (link) {
+ if (link.view) {
+ this.insertView('#nav-links', link.view).render();
+ }
+
+ }, this);
+
}
// TODO: ADD ACTIVE CLASS
diff --git a/src/fauxton/app/templates/fauxton/nav_bar.html b/src/fauxton/app/templates/fauxton/nav_bar.html
index c9800bf86..5282e68e5 100644
--- a/src/fauxton/app/templates/fauxton/nav_bar.html
+++ b/src/fauxton/app/templates/fauxton/nav_bar.html
@@ -22,9 +22,11 @@ the License.
</a>
<a class="brand" href="#">Project Fauxton</a>
<div class="nav-collapse">
- <ul class="nav pull-right">
+ <ul id="nav-links" class="nav pull-right">
<% _.each(navLinks, function(link) { %>
+ <% if (!link.view) { %>
<li><a href="<%= link.href %>"><%= link.title %></a></li>
+ <% } %>
<% }); %>
<!-- TODO: pick this up from code - nested dicts in the above -->
diff --git a/src/fauxton/settings.json.default b/src/fauxton/settings.json.default
index ef986ba29..9716ceb3d 100644
--- a/src/fauxton/settings.json.default
+++ b/src/fauxton/settings.json.default
@@ -4,7 +4,7 @@
{ "name": "logs" },
{ "name": "stats" },
{ "name": "contribute" },
- { "name": "user" }
+ { "name": "auth" }
],
"template": {
"src": "assets/index.underscore",