Skip to content

Instantly share code, notes, and snippets.

@Haraldson
Created July 15, 2014 06:21
Show Gist options
  • Save Haraldson/16a8f60fbb154e2ac72f to your computer and use it in GitHub Desktop.
Save Haraldson/16a8f60fbb154e2ac72f to your computer and use it in GitHub Desktop.
// This is a view for rendering only! Handle click events and shit in its parent view
var IssueDetailCommonMenuItemsView = Marionette.ItemView.extend(
{
template: IssueDetailMenuItemsTemplate,
onRender: function()
{
this.listenTo(this.model, 'change:scheduled change:published change:live', this.render, this);
}
});
var IssueDetailCommonMenuView = Marionette.ItemView.extend(
{
className: 'menu',
template: IssueDetailMenuTemplate,
events: {
'click button.unpublish': 'showConfirmDialog',
'click button.confirm-unpublish': 'unpublish',
'click button.delete': 'showConfirmDialog',
'click button.confirm-delete': 'purge',
'click .dialog button.dismiss': 'hideConfirmDialog'
},
onRender: function()
{
this.renderMenuItems();
},
renderMenuItems: function()
{
var menuItemsView = new MenuItemsView($.extend({}, this.options,
{
el: this.$('.menu-items')
})).render();
},
showConfirmDialog: function(e)
{
e.stopPropagation();
var $listitem = $(e.currentTarget).closest('li');
$listitem.addClass('show-dialog');
$('body').on('click.hide-confirm-dialog', function(event)
{
if(!$(event.target).closest('.dialog').length)
$listitem.removeClass('show-dialog');
});
},
hideConfirmDialog: function(e)
{
$(e.currentTarget).closest('li').removeClass('show-dialog');
$('body').off('click.hide-confirm-dialog');
},
unpublish: function()
{
this.model.unpublish();
},
onDestroy: function()
{
$('body').off('click.hide-confirm-dialog');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment