From 7817dd7b6f68ed25a11c8d2283da903bd8a3bb0b Mon Sep 17 00:00:00 2001 From: Kload Date: Mon, 23 Sep 2013 12:31:35 +0200 Subject: [PATCH] Add user edit function --- css/style.css | 2 +- js/app.js | 22 +++++++++++++++++++--- views/user_edit.ms | 15 +++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/css/style.css b/css/style.css index 8906d80f..7429eb20 100644 --- a/css/style.css +++ b/css/style.css @@ -16,7 +16,7 @@ html, body { } #slider-container { - width: 1050px; + width: 1000px; height: 100%; } diff --git a/js/app.js b/js/app.js index 73e675ec..1b1c1859 100644 --- a/js/app.js +++ b/js/app.js @@ -41,12 +41,12 @@ app = Sammy('#main', function (sam) { method = typeof method !== 'undefined' ? method : 'GET'; data = typeof data !== 'undefined' ? data : {}; auth = "Basic "+ btoa(store.get('user') +':'+ atob(store.get('password'))); - //this.swap(''); jQuery.ajax({ url: store.get('url') + uri, type: method, crossdomain: true, data: data, + traditional: true, dataType: 'json', beforeSend: function(req) { req.setRequestHeader('Authorization', auth); @@ -84,7 +84,7 @@ app = Sammy('#main', function (sam) { }); } - blockSize = $('#slider').width(); + blockSize = $('#slider').innerWidth(); if (store.get('slide') == 'back') { $('#slideBack').css('display', 'inline-block').css('margin-left', '-'+ 2*blockSize +'px'); @@ -176,7 +176,6 @@ app = Sammy('#main', function (sam) { sam.get('#/users', function (c) { c.api('/users', function(data) { - console.log(data); c.view('user_list', data); }); }); @@ -192,6 +191,23 @@ app = Sammy('#main', function (sam) { c.view('user_edit', data); }); }); + + sam.put('#/users/:user', function (c) { + params = {} + $.each(c.params.toHash(), function(key, value) { + if (value !== '') { params[key] = value; } + }); + if ($.isEmptyObject(params)) { + c.flash('fail', 'You should modify something'); + store.clear('slide'); + c.redirect('#/users/'+ c.params['user'] + '/edit'); + } else { + c.api('/users/'+ c.params['user'], function(data) { + c.flash('success', 'User successfully updated'); + c.redirect('#/users/'+ c.params['user']); + }, 'PUT', params); + } + }); }); diff --git a/views/user_edit.ms b/views/user_edit.ms index 8fac2bb7..7b465009 100644 --- a/views/user_edit.ms +++ b/views/user_edit.ms @@ -1,4 +1,4 @@ -
+
@@ -12,15 +12,18 @@
- -
- + +
+ +
+
+
- +
- +