mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
Move files
This commit is contained in:
parent
d6e1a19f16
commit
8847faaa6e
13 changed files with 58 additions and 159 deletions
14
index.html
14
index.html
|
@ -17,13 +17,13 @@
|
||||||
<a href="#/login">Grset</a>
|
<a href="#/login">Grset</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript" src="js/jquery-1.10.1.min.js"></script>
|
<script type="text/javascript" src="js/vendor/jquery-1.10.1.min.js"></script>
|
||||||
<script type="text/javascript" src="js/mustache.js"></script>
|
<script type="text/javascript" src="js/vendor/mustache.js"></script>
|
||||||
<script type="text/javascript" src="js/sammy.js"></script>
|
<script type="text/javascript" src="js/vendor/sammy.js"></script>
|
||||||
<script type="text/javascript" src="js/sammy.mustache.js"></script>
|
<script type="text/javascript" src="js/vendor/sammy.mustache.js"></script>
|
||||||
<script type="text/javascript" src="js/sammy.json.js"></script>
|
<script type="text/javascript" src="js/vendor/sammy.json.js"></script>
|
||||||
<script type="text/javascript" src="js/sammy.storage.js"></script>
|
<script type="text/javascript" src="js/vendor/sammy.storage.js"></script>
|
||||||
<script type="text/javascript" src="js/sammy.flash.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>
|
||||||
|
|
97
js/app.js
97
js/app.js
|
@ -4,47 +4,52 @@ app = Sammy('#main', function (sam) {
|
||||||
|
|
||||||
var store = new Sammy.Store({name: 'storage', type: 'session'});
|
var store = new Sammy.Store({name: 'storage', type: 'session'});
|
||||||
|
|
||||||
var flash = function (level, message) {
|
sam.helpers({
|
||||||
flashs = store.get('flash');
|
flash: function (level, message) {
|
||||||
if (!flashs) { flashs = {'info': [], 'fail': [], 'success': [] } }
|
flashs = store.get('flash');
|
||||||
flashs[level].push(message);
|
if (!flashs) { flashs = {'info': [], 'fail': [], 'success': [] } }
|
||||||
store.set('flash', flashs);
|
flashs[level].push(message);
|
||||||
|
store.set('flash', flashs);
|
||||||
|
|
||||||
html = '';
|
html = '';
|
||||||
for(lvl in flashs) {
|
for(lvl in flashs) {
|
||||||
flashs[lvl].forEach( function(msg) {
|
flashs[lvl].forEach( function(msg) {
|
||||||
html += '<div class="'+ lvl +'">'+ msg +'</div>';
|
html += '<div class="'+ lvl +'">'+ msg +'</div>';
|
||||||
});
|
});
|
||||||
}
|
|
||||||
$('#flash').html(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
var 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')));
|
|
||||||
jQuery.ajax({
|
|
||||||
url: store.get('url') + uri,
|
|
||||||
type: method,
|
|
||||||
crossdomain: true,
|
|
||||||
data: data,
|
|
||||||
dataType: 'json',
|
|
||||||
beforeSend: function(req) {
|
|
||||||
req.setRequestHeader('Authorization', auth);
|
|
||||||
}
|
}
|
||||||
})
|
$('#flash').html(html);
|
||||||
.done(function(data) {
|
},
|
||||||
console.log(data);
|
api: function (uri, callback, method, data) {
|
||||||
result = data;
|
method = typeof method !== 'undefined' ? method : 'GET';
|
||||||
})
|
data = typeof data !== 'undefined' ? data : {};
|
||||||
.fail(function() {
|
auth = "Basic "+ btoa(store.get('user') +':'+ atob(store.get('password')));
|
||||||
alert('fail');
|
jQuery.ajax({
|
||||||
result = false;
|
url: store.get('url') + uri,
|
||||||
})
|
type: method,
|
||||||
.always(function() {
|
crossdomain: true,
|
||||||
callback(result);
|
data: data,
|
||||||
});
|
dataType: 'json',
|
||||||
}
|
beforeSend: function(req) {
|
||||||
|
req.setRequestHeader('Authorization', auth);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.done(function(data) {
|
||||||
|
console.log(data);
|
||||||
|
result = data;
|
||||||
|
})
|
||||||
|
.fail(function() {
|
||||||
|
alert('fail');
|
||||||
|
result = false;
|
||||||
|
})
|
||||||
|
.always(function() {
|
||||||
|
callback(result);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
view: function (view, data) {
|
||||||
|
//data = typeof data !== 'undefined' ? data : {};
|
||||||
|
this.render('views/'+ view +'.ms', data).swap();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
sam.after(function () {
|
sam.after(function () {
|
||||||
store.set('flash', {'info': [], 'fail': [], 'success': [] });
|
store.set('flash', {'info': [], 'fail': [], 'success': [] });
|
||||||
|
@ -59,29 +64,29 @@ app = Sammy('#main', function (sam) {
|
||||||
});
|
});
|
||||||
|
|
||||||
sam.get('#/', function (c) {
|
sam.get('#/', function (c) {
|
||||||
c.render('home.ms').swap();
|
c.view('home');
|
||||||
});
|
});
|
||||||
|
|
||||||
sam.get('#/users/:user', function (c) {
|
sam.get('#/users/:user', function (c) {
|
||||||
c.swap('');
|
c.swap('');
|
||||||
api('/users/'+ c.params['user'], function(data) {
|
c.api('/users/'+ c.params['user'], function(data) {
|
||||||
c.render('user_info.ms', data).swap();
|
c.view('user_info', data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
sam.get('#/login', function (c) {
|
sam.get('#/login', function (c) {
|
||||||
c.render('login.ms').swap();
|
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', c.params['user']);
|
||||||
store.set('password', btoa(c.params['password']));
|
store.set('password', btoa(c.params['password']));
|
||||||
api('/users', function(data) {
|
c.api('/users', function(data) {
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
flash('fail', 'Error: '+ data.error);
|
c.flash('fail', 'Error: '+ data.error);
|
||||||
} else {
|
} else {
|
||||||
flash('success', 'Connected :)');
|
c.flash('success', 'Connected :)');
|
||||||
}
|
}
|
||||||
if (store.get('path')) {
|
if (store.get('path')) {
|
||||||
c.redirect(store.get('path'));
|
c.redirect(store.get('path'));
|
||||||
|
|
|
@ -1,106 +0,0 @@
|
||||||
(function (factory) {
|
|
||||||
if (typeof define === 'function' && define.amd) {
|
|
||||||
define(['jquery', 'sammy'], factory);
|
|
||||||
} else {
|
|
||||||
(window.Sammy = window.Sammy || {}).Flash = factory(window.jQuery, window.Sammy);
|
|
||||||
}
|
|
||||||
}(function ($, Sammy) {
|
|
||||||
|
|
||||||
Sammy.FlashHash = function() {
|
|
||||||
this.now = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
$.extend(Sammy.FlashHash.prototype , {
|
|
||||||
// @return [String] this Flash, rendered as an <ul>.
|
|
||||||
toHTML: function() {
|
|
||||||
var result = this._renderUL();
|
|
||||||
this.clear();
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
|
|
||||||
clear: function() {
|
|
||||||
this._clearHash(this);
|
|
||||||
this._clearHash(this.now);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Callback on redirect.
|
|
||||||
// @api private
|
|
||||||
_onRedirect: function() {
|
|
||||||
this._clearHash(this.now);
|
|
||||||
},
|
|
||||||
|
|
||||||
// clear out all flash keys
|
|
||||||
// @api private
|
|
||||||
_clearHash: function(hash) {
|
|
||||||
var key;
|
|
||||||
for (key in hash) {
|
|
||||||
if (key !== 'now' && hash.hasOwnProperty(key)) {
|
|
||||||
delete hash[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_renderUL: function() {
|
|
||||||
return '<ul class="flash">' +
|
|
||||||
this._renderLIs(this) +
|
|
||||||
this._renderLIs(this.now) +
|
|
||||||
'</ul>';
|
|
||||||
},
|
|
||||||
|
|
||||||
_renderLIs: function(hash) {
|
|
||||||
var result = '',
|
|
||||||
key;
|
|
||||||
for (key in hash) {
|
|
||||||
if (hash[key] && key !== 'now' && hash.hasOwnProperty(key)) {
|
|
||||||
result = result + '<li class="' + key + '">' + hash[key] + '</li>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Sammy.log('rendered flash: ' + result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sammy.Flash is a plugin for storing and sending status messages to the client. It's API and use
|
|
||||||
// is similar to Ruby on Rails' `flash` explained here:
|
|
||||||
// [http://apidock.com/rails/ActionController/Flash](http://apidock.com/rails/ActionController/Flash)
|
|
||||||
Sammy.Flash = function(app) {
|
|
||||||
app.flash = new Sammy.FlashHash();
|
|
||||||
|
|
||||||
// *Helper* flash(key, value) get or set a flash message that will
|
|
||||||
// be erased on the next render (but not on redirect).
|
|
||||||
//
|
|
||||||
// @param [String] key, the Flash key
|
|
||||||
// @param [String] value, the new value; optional
|
|
||||||
// @return [Sammy.FlashHash, String, null] if a key was given, the value for that key; else, the Flash
|
|
||||||
app.helper('flash', function(key, value) {
|
|
||||||
if (arguments.length === 0) {
|
|
||||||
return this.app.flash;
|
|
||||||
} else if (arguments.length === 2) {
|
|
||||||
this.app.flash[key] = value;
|
|
||||||
}
|
|
||||||
return this.app.flash[key];
|
|
||||||
});
|
|
||||||
|
|
||||||
// *Helper* flashNow(key, value) get or set a flash message that
|
|
||||||
// will be erased on the next render or redirect.
|
|
||||||
//
|
|
||||||
// @param [String] key, the Flash key
|
|
||||||
// @param [String] value, the new value; optional
|
|
||||||
// @return [String, null] the value for the given key
|
|
||||||
app.helper('flashNow', function(key, value) {
|
|
||||||
if (arguments.length === 0) {
|
|
||||||
return this.app.flash.now;
|
|
||||||
}else if (arguments.length === 2) {
|
|
||||||
this.app.flash.now[key] = value;
|
|
||||||
}
|
|
||||||
return this.app.flash.now[key];
|
|
||||||
});
|
|
||||||
|
|
||||||
app.bind('redirect', function() {
|
|
||||||
this.app.flash._onRedirect();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return Sammy.Flash;
|
|
||||||
|
|
||||||
}));
|
|
0
js/mustache.js → js/vendor/mustache.js
vendored
0
js/mustache.js → js/vendor/mustache.js
vendored
0
js/sammy.js → js/vendor/sammy.js
vendored
0
js/sammy.js → js/vendor/sammy.js
vendored
0
js/sammy.json.js → js/vendor/sammy.json.js
vendored
0
js/sammy.json.js → js/vendor/sammy.json.js
vendored
Loading…
Add table
Reference in a new issue