зеркало из https://github.com/mozilla/FlightDeck.git
moved Admin.js into a Shipyard app
This commit is contained in:
Родитель
07cf5fdf89
Коммит
fdae99db2b
|
@ -35,7 +35,15 @@
|
|||
'update_package_url':'{{ url('admin_update_package') }}',
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="/media/base/js/Admin.js" ></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block shipyardjs %}
|
||||
{{ shipyard("/media/base/js/admin/") }}
|
||||
{% endblock %}
|
||||
|
||||
{% block page_domready %}
|
||||
var admin = require('admin');
|
||||
admin.init(admin_settings);
|
||||
{% endblock %}
|
||||
|
||||
{% block app_content %}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
window.addEvent('domready', function(e){
|
||||
var setMsg = function(msg){
|
||||
var elem = $('package_msg');
|
||||
elem.set('html', msg);
|
||||
setTimeout(function(){
|
||||
elem.set('html','');
|
||||
},2000);
|
||||
}
|
||||
$('btn_find_package').addEvent('click', function(e){
|
||||
var r = new Request({
|
||||
url: admin_settings.get_package_url,
|
||||
onSuccess: function(p){
|
||||
$('package_item').set('html',p);
|
||||
},
|
||||
onFailure: function(err){
|
||||
console.log(err);
|
||||
setMsg(err.status + " " + err.statusText);
|
||||
}
|
||||
});
|
||||
r.get('package_id='+ $('txt_package_id').value);
|
||||
|
||||
});
|
||||
|
||||
var updatePackage = function(elem, field, callback){
|
||||
var id = elem.getParent('.package').getElement('.package_id').value,
|
||||
enabled = elem.getParent().hasClass('pressed'),
|
||||
r = new Request({
|
||||
url: admin_settings.update_package_url,
|
||||
method: 'post',
|
||||
onSuccess: function(p){
|
||||
setMsg("updated");
|
||||
elem.getParent().toggleClass('pressed');
|
||||
if (callback) callback();
|
||||
},
|
||||
onFailure: function(err){
|
||||
if(err.status == 404){
|
||||
$('package_item').set('html', '');
|
||||
}
|
||||
setMsg(err.status + " " + err.statusText);
|
||||
}
|
||||
});
|
||||
r.send('package_id='+id+'&'+field+'='+!enabled);
|
||||
};
|
||||
|
||||
$('package_item').addEvent('click:relay(.UI_Package_Featured a)', function(e){
|
||||
e.stop();
|
||||
updatePackage(this, 'featured')
|
||||
});
|
||||
$('package_item').addEvent('click:relay(.UI_Package_Example a)', function(e){
|
||||
e.stop();
|
||||
updatePackage(this, 'example')
|
||||
});
|
||||
});
|
|
@ -0,0 +1,75 @@
|
|||
var Request = require('shipyard/http/Request'),
|
||||
dom = require('shipyard/dom');
|
||||
|
||||
var admin_settings;
|
||||
var PRESSED = 'pressed';
|
||||
|
||||
function setMsg(msg) {
|
||||
var elem = dom.$('package_msg');
|
||||
elem.set('html', msg);
|
||||
setTimeout(function() {
|
||||
elem.set('html', '');
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function updatePackage(elem, field, callback) {
|
||||
var id = elem.getParent('.package').getElement('.package_id').get('value'),
|
||||
parent = elem.getParent(),
|
||||
enabled = parent.hasClass(PRESSED),
|
||||
data = {
|
||||
package_id: id
|
||||
};
|
||||
data[field] = !enabled;
|
||||
new Request({
|
||||
url: admin_settings.update_package_url,
|
||||
method: 'post',
|
||||
data: data,
|
||||
onSuccess: function() {
|
||||
setMsg('updated');
|
||||
if (enabled) {
|
||||
parent.removeClass(PRESSED);
|
||||
} else {
|
||||
parent.addClass(PRESSED);
|
||||
}
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
onFailure: function() {
|
||||
if (this.xhr.status === 404) {
|
||||
dom.$('package_item').set('html', '');
|
||||
}
|
||||
setMsg(this.xhr.status + " " + this.xhr.statusText);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
exports.init = function(settings) {
|
||||
admin_settings = settings;
|
||||
|
||||
var item = dom.$('package_item');
|
||||
item.delegate('.UI_Package_Featured a', 'click', function(e) {
|
||||
e.stop();
|
||||
updatePackage(this, 'featured');
|
||||
});
|
||||
item.delegate('.UI_Package_Example a', 'click', function(e) {
|
||||
e.stop();
|
||||
updatePackage(this, 'example');
|
||||
});
|
||||
|
||||
dom.$('btn_find_package').addListener('click', function(e) {
|
||||
new Request({
|
||||
url: admin_settings.get_package_url,
|
||||
method: 'get',
|
||||
data: {
|
||||
package_id: dom.$('txt_package_id').get('value')
|
||||
},
|
||||
onSuccess: function(text) {
|
||||
item.set('html', text);
|
||||
},
|
||||
onFailure: function() {
|
||||
setMsg(this.xhr.status + ' ' + this.xhr.statusText);
|
||||
}
|
||||
}).send();
|
||||
});
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "admin",
|
||||
|
||||
"shipyard": {
|
||||
"dependencies": {
|
||||
"flightdeck": "../flightdeck"
|
||||
},
|
||||
"mini_require": true,
|
||||
"target": "../admin-min.js"
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче