Add user edit function

This commit is contained in:
Kload 2013-09-23 12:31:35 +02:00
parent 9263c6a318
commit 7817dd7b6f
3 changed files with 29 additions and 10 deletions

View file

@ -16,7 +16,7 @@ html, body {
} }
#slider-container { #slider-container {
width: 1050px; width: 1000px;
height: 100%; height: 100%;
} }

View file

@ -41,12 +41,12 @@ app = Sammy('#main', function (sam) {
method = typeof method !== 'undefined' ? method : 'GET'; method = typeof method !== 'undefined' ? method : 'GET';
data = typeof data !== 'undefined' ? data : {}; data = typeof data !== 'undefined' ? data : {};
auth = "Basic "+ btoa(store.get('user') +':'+ atob(store.get('password'))); auth = "Basic "+ btoa(store.get('user') +':'+ atob(store.get('password')));
//this.swap('<img src="img/ajax-loader.gif" />');
jQuery.ajax({ jQuery.ajax({
url: store.get('url') + uri, url: store.get('url') + uri,
type: method, type: method,
crossdomain: true, crossdomain: true,
data: data, data: data,
traditional: true,
dataType: 'json', dataType: 'json',
beforeSend: function(req) { beforeSend: function(req) {
req.setRequestHeader('Authorization', auth); req.setRequestHeader('Authorization', auth);
@ -84,7 +84,7 @@ app = Sammy('#main', function (sam) {
}); });
} }
blockSize = $('#slider').width(); blockSize = $('#slider').innerWidth();
if (store.get('slide') == 'back') { if (store.get('slide') == 'back') {
$('#slideBack').css('display', 'inline-block').css('margin-left', '-'+ 2*blockSize +'px'); $('#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) { sam.get('#/users', function (c) {
c.api('/users', function(data) { c.api('/users', function(data) {
console.log(data);
c.view('user_list', data); c.view('user_list', data);
}); });
}); });
@ -192,6 +191,23 @@ app = Sammy('#main', function (sam) {
c.view('user_edit', data); 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);
}
});
}); });

View file

@ -1,4 +1,4 @@
<form action="#/users/{{Username}}/edit" id="form" method="put" class="form-horizontal"> <form action="#/users/{{Username}}" method="PUT" class="form-horizontal">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
@ -12,15 +12,18 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="username" class="col-sm-4 control-label">Fullname</label> <label for="firstname" class="col-sm-4 control-label">Fullname</label>
<div class="col-sm-8"> <div class="col-sm-4">
<input type="text" name="username" class="form-control" placeholder="{{Fullname}}"> <input type="text" name="firstname" class="form-control" placeholder="{{Firstname}}">
</div>
<div class="col-sm-4">
<input type="text" name="lastname" class="form-control" placeholder="{{Lastname}}">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="username" class="col-sm-4 control-label">Mail</label> <label for="mail" class="col-sm-4 control-label">Mail</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="email" name="username" class="form-control" placeholder="{{Mail}}"> <input type="email" name="mail" class="form-control" placeholder="{{Mail}}">
</div> </div>
</div> </div>
</div> </div>