Add tools section, with adminpw tool.

This commit is contained in:
Thomas Lebeau 2014-02-20 12:36:16 +01:00 committed by opi
parent 87f76d86c3
commit 72a503f266
3 changed files with 100 additions and 0 deletions

View file

@ -266,6 +266,7 @@ app = Sammy('#main', function (sam) {
{name: "Applications", path: '#/apps'},
{name: "Services", path: '#/services'},
{name: "Monitoring", path: '#/monitor'},
{name: "Tools", path: '#/tools'},
]};
c.view('home', data);
@ -634,6 +635,49 @@ app = Sammy('#main', function (sam) {
});
/**
* Tools
*
*/
sam.get('#/tools', function (c) {
// Available tools
data = {links: [
{name: "Change administration password", path: '#/tools/adminpw'},
]};
c.view('tools_list', data);
});
// Update administration password
sam.get('#/tools/adminpw', function (c) {
c.view('tools_adminpw');
});
sam.put('#/tools/adminpw', 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('#/tools/adminpw');
} else if (params['new_password'] !== params['confirm_new_password']) {
c.flash('fail', 'Your password didn\'t match');
store.clear('slide');
c.redirect('#/tools/adminpw');
} else {
// Remove useless variable
delete params['confirm_new_password'];
// Update password and redirect to the home
c.api('/adminpw', function(data) { // http://api.yunohost.org/#!/tools/tools_adminpw_put_3
c.redirect('#/');
}, 'PUT', params);
}
});
});

38
views/tools_adminpw.ms Normal file
View file

@ -0,0 +1,38 @@
<div class="pull-left">
<a href="#/tools" class="btn btn-default slide back"><span class="glyphicon glyphicon-chevron-left"></span> Tools</a>
</div>
<div class="clearfix"></div>
<div class="view-title">Change administration password</div>
<div class="br"></div>
<form action="#/tools/adminpw" method="PUT" class="form-horizontal">
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<label for="old_password" class="col-sm-3 control-label">Current password</label>
<div class="col-sm-5 col-xs-12">
<input type="password" name="old_password" class="form-control" placeholder="Enter your current password"/>
</div>
</div>
<hr />
<div class="form-group">
<label for="new_password" class="col-sm-3 control-label">New password</label>
<div class="col-sm-5 col-xs-12">
<input type="password" name="new_password" class="form-control" placeholder="Enter the new password"/>
</div>
</div>
<div class="form-group">
<label for="confirm_new_password" class="col-sm-3 control-label">Confirm</label>
<div class="col-sm-5 col-xs-12">
<input type="password" name="confirm_new_password" class="form-control" placeholder="Confirm the new password"/>
</div>
</div>
</div>
</div>
<div class="text-center">
<input type="submit" class="btn btn-success slide back" value="Save">
</div>
</form>

18
views/tools_list.ms Normal file
View file

@ -0,0 +1,18 @@
<div class="pull-left">
<a href="#/" class="btn btn-default slide back"><span class="glyphicon glyphicon-chevron-left"></span> Menu</a>
</div>
<div class="clearfix"></div>
<div class="view-title">Tools</div>
<div class="br"></div>
<div class="list-group">
{{#links}}
<a href="{{path}}" class="list-group-item slide">
<h4 class="pull-left list-group-item-heading">{{name}}</h4>
<span class="glyphicon glyphicon-chevron-right pull-right"></span>
<div class="clearfix"></div>
</a>
{{/links}}
</div>