Skip to content

Instantly share code, notes, and snippets.

@luniki
Created September 26, 2016 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luniki/d34846a18d57ad2e8929f6b76bae354a to your computer and use it in GitHub Desktop.
Save luniki/d34846a18d57ad2e8929f6b76bae354a to your computer and use it in GitHub Desktop.
STUDIP.Dialog und Backbone.View
import Backbone from 'backbone'
import _ from 'underscore'
import Promise from 'bluebird'
const showDialog = function (backboneView, dialogOptions) {
return new Promise(function (resolve, reject) {
const hygenicDialogClass = _.uniqueId('cliqr--dialog-')
Backbone.$(document).on(
`dialog-update.${hygenicDialogClass}`,
(event, data) => {
if (data.dialog.closest('.ui-dialog').hasClass(hygenicDialogClass)) {
data.dialog.append(backboneView.$el).dialog('open')
resolve(() => data.dialog.dialog('close'))
}
})
Backbone.$(document).on(
`dialogcreate.${hygenicDialogClass}`,
`.${hygenicDialogClass}`,
function (event, data) {
Backbone.$(event.target).dialog('option', 'autoOpen', false)
}
)
Backbone.$(document).on(
`dialogclose.${hygenicDialogClass}`,
`.${hygenicDialogClass}`,
function (event) {
if (Backbone.$(this).hasClass(hygenicDialogClass)) {
backboneView.remove()
Backbone.$(document).off(`.${hygenicDialogClass}`)
}
}
)
window.STUDIP.Dialog.show('', {
buttons: null,
id: hygenicDialogClass,
...dialogOptions,
dialogClass: `cliqr--dialog ${hygenicDialogClass}`
})
})
}
export default showDialog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment