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="Content-Type" content="text/html; charset=utf-8" />
|
||||||
<meta http-equiv="cache-control" content="no-cache" />
|
<meta http-equiv="cache-control" content="no-cache" />
|
||||||
<title>YunoHost admin</title>
|
<title>YunoHost admin</title>
|
||||||
|
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body style="padding: 20px">
|
||||||
<h1>YunoHost</h1>
|
<h1><a class="logo" href="#/">YunoHost</a></h1>
|
||||||
|
<br />
|
||||||
<div id="flash">
|
<div id="flash">
|
||||||
</div>
|
</div>
|
||||||
<div id="content">
|
<br />
|
||||||
<a href="#/">Greet</a>
|
|
||||||
</div>
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<a href="#/login">Grset</a>
|
<a href="#/login">Grset</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,7 +22,6 @@
|
||||||
<script type="text/javascript" src="js/vendor/sammy.mustache.js"></script>
|
<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.json.js"></script>
|
||||||
<script type="text/javascript" src="js/vendor/sammy.storage.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>
|
<script type="text/javascript" src="js/app.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
71
js/app.js
71
js/app.js
|
@ -1,10 +1,23 @@
|
||||||
app = Sammy('#main', function (sam) {
|
app = Sammy('#main', function (sam) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sammy Configuration
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// Plugins
|
||||||
sam.use('Mustache', 'ms');
|
sam.use('Mustache', 'ms');
|
||||||
|
|
||||||
|
// Initialize storage
|
||||||
var store = new Sammy.Store({name: 'storage', type: 'session'});
|
var store = new Sammy.Store({name: 'storage', type: 'session'});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helpers
|
||||||
|
*
|
||||||
|
*/
|
||||||
sam.helpers({
|
sam.helpers({
|
||||||
|
|
||||||
|
// Flash helper to diplay instant notifications
|
||||||
flash: function (level, message) {
|
flash: function (level, message) {
|
||||||
flashs = store.get('flash');
|
flashs = store.get('flash');
|
||||||
if (!flashs) { flashs = {'info': [], 'fail': [], 'success': [] } }
|
if (!flashs) { flashs = {'info': [], 'fail': [], 'success': [] } }
|
||||||
|
@ -19,10 +32,13 @@ app = Sammy('#main', function (sam) {
|
||||||
}
|
}
|
||||||
$('#flash').html(html);
|
$('#flash').html(html);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// API connection helper
|
||||||
api: function (uri, callback, method, data) {
|
api: function (uri, callback, method, data) {
|
||||||
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,
|
||||||
|
@ -45,42 +61,60 @@ app = Sammy('#main', function (sam) {
|
||||||
callback(result);
|
callback(result);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Render view (cross-browser)
|
||||||
view: function (view, data) {
|
view: function (view, data) {
|
||||||
//data = typeof data !== 'undefined' ? data : {};
|
|
||||||
this.render('views/'+ view +'.ms', data).swap();
|
this.render('views/'+ view +'.ms', data).swap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sam.after(function () {
|
|
||||||
store.set('flash', {'info': [], 'fail': [], 'success': [] });
|
|
||||||
});
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters
|
||||||
|
*
|
||||||
|
*/
|
||||||
sam.before({except: {path: '#/login'}}, function (req) {
|
sam.before({except: {path: '#/login'}}, function (req) {
|
||||||
|
|
||||||
|
// Store path for further redirections
|
||||||
store.set('path', req.path);
|
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');
|
req.redirect('#/login');
|
||||||
return false;
|
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) {
|
sam.get('#/', function (c) {
|
||||||
c.view('home');
|
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) {
|
sam.get('#/login', function (c) {
|
||||||
c.view('login');
|
c.view('login');
|
||||||
});
|
});
|
||||||
|
|
||||||
sam.post('#/login', function (c) {
|
sam.post('#/login', function (c) {
|
||||||
store.set('url', c.params['url']);
|
store.set('url', c.params['url']);
|
||||||
store.set('user', c.params['user']);
|
store.set('user', 'admin');
|
||||||
store.set('password', btoa(c.params['password']));
|
store.set('password', btoa(c.params['password']));
|
||||||
c.api('/users', function(data) {
|
c.api('/users', function(data) {
|
||||||
if (data.error) {
|
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 () {
|
$(document).ready(function () {
|
||||||
app.run('#/');
|
app.run('#/');
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,15 +1,5 @@
|
||||||
<form action="/index.html#/login" id="form" method="post">
|
<form action="#/login" id="form" method="post">
|
||||||
<p>
|
<input type="text" name="url" placeholder="YunoHost API URL" /><br />
|
||||||
<label>Url:</label>
|
<input type="password" name="password" placeholder="Password" /><br />
|
||||||
<input type="text" name="url" />
|
<input id="submit" type="submit" value="Login" class="btn btn-primary"/>
|
||||||
</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>
|
</form>
|
||||||
|
|
Loading…
Add table
Reference in a new issue