| |   |
60 | 60 | return false; |
61 | 61 | } |
62 | 62 | var id = $(event.target).parent('.remove').attr('for'); |
var success_template = _.template($('#success-notif').html()); |
var fail_template = _.template($('#fail-notif').html()); |
65 | 63 | //console.log('remove', id); |
66 | 64 | M.pages.get(id).destroy({ |
67 | 65 | success: function(model, response) { |
… | … | |
70 | 70 | if(M.editor.pageview) { |
71 | 71 | M.editor.pageview.remove(); |
72 | 72 | } |
$('#notifications').html(success_template({ |
title: 'Deleted', |
msg: '' |
})); |
M.editor.notifs.show('success', 'Deleted', ''); |
77 | 74 | }, |
78 | 75 | error: function(model, xhr) { |
79 | 76 | M.editor.hideOverlay(); |
80 | 77 | console.log('failed', model, xhr); |
$('#notifications').html(fail_template({ |
title: 'Error', |
msg: 'Failed to delete. Please try again.' |
})); |
var msg = 'Failed to delete. Please try again.'; |
M.editor.notifs.show('fail', 'Error!', msg); |
85 | 80 | } |
86 | 81 | }); |
87 | 82 | M.editor.showOverlay(); |
… | … | |
232 | 232 | return false; |
233 | 233 | }, |
234 | 234 | updatePage: function() { |
var success_template = _.template($('#success-notif').html()); |
var fail_template = _.template($('#fail-notif').html()); |
|
238 | 235 | var name = $('#name').val(); |
239 | 236 | var title = $('#title').val(); |
240 | 237 | var children = $('#children').val(); |
… | … | |
261 | 261 | //model.id = response.page.id; |
262 | 262 | //console.log(model); |
263 | 263 | M.pagelistview.render(); |
$('#notifications').html(success_template({ |
title: 'Saved', |
msg: '' |
})); |
M.editor.notifs.show('success', 'Saved', ''); |
268 | 265 | }, |
269 | 266 | error: function(model, xhr) { |
270 | 267 | M.editor.hideOverlay(); |
271 | 268 | model.set(response.page); |
272 | 269 | console.log('failed', model, xhr); |
$('#notifications').html(fail_template({ |
title: 'Error!', |
msg: 'Something went wrong, and the page could not be updated' |
})); |
var msg = 'Something went wrong, and the page could not be updated'; |
M.editor.notifs.show('fail', 'Error!', msg); |
277 | 272 | } |
278 | 273 | }); |
279 | 274 | M.editor.showOverlay(); |
… | … | |
348 | 348 | })); |
349 | 349 | if(this.model.get('src')) { |
350 | 350 | var plugin_type = this.model.get('plugin_type'); |
plugin_type = (plugin_type === 'js') ? 'javascript': 'css'; |
plugin_type = (plugin_type === 'js') ? 'javascript' : 'css'; |
352 | 352 | this.model.getCode(function(data) { |
353 | 353 | $('#plugin-edit').html(escapeHtml(data)); |
354 | 354 | M.editor.code.init('plugin-edit', plugin_type); |
… | … | |
513 | 513 | }, |
514 | 514 | saveMenu: function() { |
515 | 515 | //console.log('saving menu..'); |
var success_template = _.template($('#success-notif').html()); |
var fail_template = _.template($('#fail-notif').html()); |
|
519 | 516 | if($('#custom-menu').is(':checked')) { |
520 | 517 | var html = $('#menu').val().trim() || ''; |
521 | 518 | this.model.set({'customMenu': true, 'html': html}); |
… | … | |
526 | 526 | success: function(model, response) { |
527 | 527 | //console.log(model, response); |
528 | 528 | M.editor.hideOverlay(); |
$('#notifications').html(success_template({ |
title: 'Saved', |
msg: '' |
})); |
M.editor.notifs.show('success', 'Saved', ''); |
533 | 530 | |
534 | 531 | }, |
535 | 532 | error: function(xhr, response) { |
536 | 533 | M.editor.hideOverlay(); |
$('#notifications').html(fail_template({ |
title: 'Error!', |
msg: 'Something went wrong, and the page could not be updated' |
})); |
var msg = 'Something went wrong, and the page could not be updated'; |
M.editor.notifs.show('fail', 'Error!', msg); |
541 | 536 | } |
542 | 537 | }); |
543 | 538 | //alert('end of save menu'); |
… | … | |
540 | 540 | } |
541 | 541 | }); |
542 | 542 | |
/* Notification view */ |
var NotificationView = Backbone.View.extend({ |
initialize: function(opts) { |
try { |
this.el = opts.el; |
} |
catch(e) { |
throw new Error(this.usage()); |
return; |
} |
this.template = _.template($('#notif-template').html()); |
this.el = opts.el; |
this.delayTime = opts.delay || 3000; // a default delay value |
}, |
render: function(type, title, msg) { |
$(this.el).html(this.template({ |
type: (type === 'fail') ? 'danger' : 'success', |
title: title, |
msg: msg |
//autohide the notif after a delay |
})).show(200).delay(this.delayTime).hide(500); |
}, |
usage: function() { |
return 'Missing or invalid parameters.\n Valid Params: '+ |
'\n@el: (required) a JQuery HTML element, inside which the notifaction'+ |
' will be rendered'+ |
'\n@delay: (optional) a delay time, after which the notification'+ |
' will be hidden'; |
} |
}); |
543 | 573 | |
/* The global editor object. |
* All high-level editor operations are defined here. |
*/ |
544 | 577 | M.editor = { |
545 | 578 | init: function() { |
546 | 579 | M.pages = new Pages(M.site_content.content); |
var pagelistview = new PageListView(); |
pagelistview.render(); |
/*M.pages.on('add', function(page) { |
pagelistview.render(); |
});*/ |
M.pagelistview = pagelistview; |
M.pagelistview = new PageListView(); |
M.pagelistview.render(); |
// initialize the notfications for the editor |
this.notifs.notifview = new NotificationView({ |
el: $('#notifications'), |
}); |
553 | 586 | }, |
// the wysiwig editor sub-object |
554 | 588 | wysiwyg: { |
555 | 589 | init: function($selector) { |
556 | 590 | tinymce.init({ |
… | … | |
613 | 613 | cleanUp: function($selector) { |
614 | 614 | } |
615 | 615 | }, |
// the code editor |
616 | 617 | code: { |
617 | 618 | _editor: false, |
618 | 619 | init: function(id, mode) { |
… | … | |
632 | 632 | return data; |
633 | 633 | }, |
634 | 634 | cleanUp: function(id) { |
} |
}, |
//editor notifications |
notifs: { |
// init the notif view when the DOM is ready, in editor.init |
notifview: null, |
show: function(type, title, msg) { |
this.notifview.render(type, title, msg); |
635 | 643 | } |
636 | 644 | }, |
637 | 645 | showOverlay: function() { |