mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
Prettify & document
This commit is contained in:
parent
8847faaa6e
commit
f7832aefe8
7 changed files with 853 additions and 34 deletions
786
css/bootstrap.min.css
vendored
Normal file
786
css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
img/ajax-loader.gif
Normal file
BIN
img/ajax-loader.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
img/glyphicons-halflings-white.png
Normal file
BIN
img/glyphicons-halflings-white.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
BIN
img/glyphicons-halflings.png
Normal file
BIN
img/glyphicons-halflings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
12
index.html
12
index.html
|
@ -4,15 +4,14 @@
|
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="cache-control" content="no-cache" />
|
||||
<title>YunoHost admin</title>
|
||||
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||
</head>
|
||||
<body>
|
||||
<h1>YunoHost</h1>
|
||||
|
||||
<body style="padding: 20px">
|
||||
<h1><a class="logo" href="#/">YunoHost</a></h1>
|
||||
<br />
|
||||
<div id="flash">
|
||||
</div>
|
||||
<div id="content">
|
||||
<a href="#/">Greet</a>
|
||||
</div>
|
||||
<br />
|
||||
<div id="main">
|
||||
<a href="#/login">Grset</a>
|
||||
</div>
|
||||
|
@ -23,7 +22,6 @@
|
|||
<script type="text/javascript" src="js/vendor/sammy.mustache.js"></script>
|
||||
<script type="text/javascript" src="js/vendor/sammy.json.js"></script>
|
||||
<script type="text/javascript" src="js/vendor/sammy.storage.js"></script>
|
||||
<script type="text/javascript" src="js/vendor/sammy.flash.js"></script>
|
||||
<script type="text/javascript" src="js/app.js"></script>
|
||||
|
||||
</body>
|
||||
|
|
71
js/app.js
71
js/app.js
|
@ -1,10 +1,23 @@
|
|||
app = Sammy('#main', function (sam) {
|
||||
|
||||
/**
|
||||
* Sammy Configuration
|
||||
*
|
||||
*/
|
||||
// Plugins
|
||||
sam.use('Mustache', 'ms');
|
||||
|
||||
// Initialize storage
|
||||
var store = new Sammy.Store({name: 'storage', type: 'session'});
|
||||
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*
|
||||
*/
|
||||
sam.helpers({
|
||||
|
||||
// Flash helper to diplay instant notifications
|
||||
flash: function (level, message) {
|
||||
flashs = store.get('flash');
|
||||
if (!flashs) { flashs = {'info': [], 'fail': [], 'success': [] } }
|
||||
|
@ -19,10 +32,13 @@ app = Sammy('#main', function (sam) {
|
|||
}
|
||||
$('#flash').html(html);
|
||||
},
|
||||
|
||||
// API connection helper
|
||||
api: function (uri, callback, method, data) {
|
||||
method = typeof method !== 'undefined' ? method : 'GET';
|
||||
data = typeof data !== 'undefined' ? data : {};
|
||||
auth = "Basic "+ btoa(store.get('user') +':'+ atob(store.get('password')));
|
||||
this.swap('<img src="img/ajax-loader.gif" />');
|
||||
jQuery.ajax({
|
||||
url: store.get('url') + uri,
|
||||
type: method,
|
||||
|
@ -45,42 +61,60 @@ app = Sammy('#main', function (sam) {
|
|||
callback(result);
|
||||
});
|
||||
},
|
||||
|
||||
// Render view (cross-browser)
|
||||
view: function (view, data) {
|
||||
//data = typeof data !== 'undefined' ? data : {};
|
||||
this.render('views/'+ view +'.ms', data).swap();
|
||||
}
|
||||
});
|
||||
|
||||
sam.after(function () {
|
||||
store.set('flash', {'info': [], 'fail': [], 'success': [] });
|
||||
});
|
||||
|
||||
/**
|
||||
* Filters
|
||||
*
|
||||
*/
|
||||
sam.before({except: {path: '#/login'}}, function (req) {
|
||||
|
||||
// Store path for further redirections
|
||||
store.set('path', req.path);
|
||||
if (!store.get('user')) {
|
||||
|
||||
// Redirect to login page if no credentials are stored
|
||||
if (!store.get('password')) {
|
||||
req.redirect('#/login');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear flash display
|
||||
if (!store.get('flash')) {
|
||||
$('#flash').html('');
|
||||
}
|
||||
});
|
||||
|
||||
sam.after(function () {
|
||||
|
||||
// Clear flash notifications
|
||||
store.clear('flash');
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Routes
|
||||
*
|
||||
* Note: var "c" is Sammy's route context
|
||||
* @doc http://sammyjs.org/docs/api/#Sammy.EventContext
|
||||
*
|
||||
*/
|
||||
sam.get('#/', function (c) {
|
||||
c.view('home');
|
||||
});
|
||||
|
||||
sam.get('#/users/:user', function (c) {
|
||||
c.swap('');
|
||||
c.api('/users/'+ c.params['user'], function(data) {
|
||||
c.view('user_info', data);
|
||||
});
|
||||
});
|
||||
|
||||
sam.get('#/login', function (c) {
|
||||
c.view('login');
|
||||
});
|
||||
|
||||
sam.post('#/login', function (c) {
|
||||
store.set('url', c.params['url']);
|
||||
store.set('user', c.params['user']);
|
||||
store.set('user', 'admin');
|
||||
store.set('password', btoa(c.params['password']));
|
||||
c.api('/users', function(data) {
|
||||
if (data.error) {
|
||||
|
@ -95,9 +129,20 @@ app = Sammy('#main', function (sam) {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
sam.get('#/users/:user', function (c) {
|
||||
c.swap('');
|
||||
c.api('/users/'+ c.params['user'], function(data) {
|
||||
c.view('user_info', data);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Run the app
|
||||
*
|
||||
*/
|
||||
$(document).ready(function () {
|
||||
app.run('#/');
|
||||
});
|
||||
|
|
|
@ -1,15 +1,5 @@
|
|||
<form action="/index.html#/login" id="form" method="post">
|
||||
<p>
|
||||
<label>Url:</label>
|
||||
<input type="text" name="url" />
|
||||
</p>
|
||||
<p>
|
||||
<label>Login:</label>
|
||||
<input type="text" name="user" />
|
||||
</p>
|
||||
<p>
|
||||
<label>Password:</label>
|
||||
<input type="password" name="password" />
|
||||
</p>
|
||||
<input id="submit" type="submit" value="Gogogo" />
|
||||
<form action="#/login" id="form" method="post">
|
||||
<input type="text" name="url" placeholder="YunoHost API URL" /><br />
|
||||
<input type="password" name="password" placeholder="Password" /><br />
|
||||
<input id="submit" type="submit" value="Login" class="btn btn-primary"/>
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue