app/assets/javascripts/admin/common.js in enki-engine-0.0.4 vs app/assets/javascripts/admin/common.js in enki-engine-0.0.5
- old
+ new
@@ -1,33 +1,33 @@
+var undo_stack = [];
+
jQuery.delegate = function(rules) {
return function(e) {
var target = $(e.target);
- for (var selector in rules)
- if (target.is(selector)) return rules[selector].apply(this, $.makeArray(arguments));
- }
-}
+ for (var selector in rules) {
+ if (target.is(selector)) {
+ return rules[selector].apply(this, $.makeArray(arguments));
+ }
+ }
+ };
+};
$(document).ajaxSend(function(e, xhr, options) {
var token = $("meta[name='csrf-token']").attr("content");
xhr.setRequestHeader("X-CSRF-Token", token);
});
-function restripe() {
- $('table tr:odd').removeClass('alt');
- $('table tr:even').addClass('alt');
-}
-
function asyncDeleteForm(obj, options) {
$.ajax($.extend({
type: "DELETE",
url: obj.attr('action'),
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept", "application/json");
},
dataType: 'json',
success: function(msg){
- display = msg.undo_message
+ display = msg.undo_message;
if (msg.undo_path) {
display += '<span class="undo-link"> (<a class="undo-link" href="' + msg.undo_path + '">undo</a>)</span>';
undo_stack.push(msg.undo_path);
}
humanMsg.displayMsg(display);
@@ -54,11 +54,13 @@
}
}, options || {}));
// Assume success and remove undo link
$('a.undo-link[href=' + path + ']').parent('span').hide();
- undo_stack = jQuery.grep(undo_stack, function(e) { return e != path });
+ undo_stack = jQuery.grep(undo_stack, function(e) {
+ return e != path;
+ });
}
function asyncUndoBehaviour(options) {
$('#humanMsgLog').click($.delegate({
'a.undo-link': function(e) {
@@ -67,26 +69,24 @@
}
}));
jQuery.each(["Ctrl+Z", "Meta+Z"], function () {
shortcut.add(this, function() {
item = undo_stack.pop();
- if (item)
- processUndo(item, options)
- else
+ if (item) {
+ processUndo(item, options);
+ } else {
humanMsg.displayMsg("Nothing to undo");
+ }
});
});
}
-var undo_stack = new Array();
-
function onDeleteFormClick() {
asyncDeleteForm($(this));
// Assume success and remove item
$(this).parent('td').parent('tr').remove();
- restripe();
return false;
}
function destroyAndUndoBehaviour(type) {
return function (){
@@ -96,14 +96,20 @@
$.get('/admin/' + type + '/' + msg.obj.id, function(data) {
$('table tbody').append(data);
$('form.delete-item').unbind('submit', onDeleteFormClick);
$('form.delete-item').submit(onDeleteFormClick);
- restripe();
});
- },
+ }
});
$('form.delete-item').submit(onDeleteFormClick);
- }
+ };
}
+$(document).ready(function() {
+ $(['posts', 'comments', 'pages']).each(function() {
+ if ($('#' + this).length > 0) {
+ destroyAndUndoBehaviour(this)();
+ }
+ });
+});