diff --git a/src/sunstone/public/app/app.js b/src/sunstone/public/app/app.js index 8865d637fc..4b204b0552 100644 --- a/src/sunstone/public/app/app.js +++ b/src/sunstone/public/app/app.js @@ -47,7 +47,8 @@ define(function(require) { var _commonDialogs = [ require('utils/dialogs/confirm'), - require('utils/dialogs/confirm-with-select') + require('utils/dialogs/confirm-with-select'), + require('utils/dialogs/generic-confirm') ] Sunstone.addDialogs(_commonDialogs); diff --git a/src/sunstone/public/app/utils/dialogs/generic-confirm.js b/src/sunstone/public/app/utils/dialogs/generic-confirm.js new file mode 100644 index 0000000000..c0fa2e137f --- /dev/null +++ b/src/sunstone/public/app/utils/dialogs/generic-confirm.js @@ -0,0 +1,86 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./generic-confirm/html'); + var Sunstone = require('sunstone'); + var Locale = require('utils/locale'); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./generic-confirm/dialogId'); + + /* + CONSTRUCTOR + */ + + function Dialog() { + this.dialogId = DIALOG_ID; + BaseDialog.call(this); + } + + Dialog.DIALOG_ID = DIALOG_ID; + Dialog.prototype = Object.create(BaseDialog.prototype); + Dialog.prototype.constructor = Dialog; + Dialog.prototype.html = _html; + Dialog.prototype.onShow = _onShow; + Dialog.prototype.setup = _setup; + Dialog.prototype.setParams = _setParams; + + return Dialog; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({dialogId: this.dialogId}); + } + + /** + * @param {object} params. + * - params.header : Optional, html string + * - params.body : Optional, html string + * - params.question : Optional, html string + * - params.submit : Mandatory, function to call if user confirms + */ + function _setParams(params) { + this.params = params; + } + + function _setup(context) { + var that = this; + + $('#' + DIALOG_ID + 'Form', context).submit(function() { + Sunstone.getDialog(DIALOG_ID).hide(); + + if (that.params.submit){ + that.params.submit(this); + } + + return false; + }); + + return false; + } + + function _onShow(context) { + if (this.params.header){ + $("#header", context).html(this.params.header); + } + + if (this.params.body){ + $("#body", context).html(this.params.body); + } + + if (this.params.question){ + $("#question", context).html(this.params.question); + } + + return false; + } +}); diff --git a/src/sunstone/public/app/utils/dialogs/generic-confirm/dialogId.js b/src/sunstone/public/app/utils/dialogs/generic-confirm/dialogId.js new file mode 100644 index 0000000000..9fd6317d05 --- /dev/null +++ b/src/sunstone/public/app/utils/dialogs/generic-confirm/dialogId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'genericConfirmDialog'; +}); \ No newline at end of file diff --git a/src/sunstone/public/app/utils/dialogs/generic-confirm/html.hbs b/src/sunstone/public/app/utils/dialogs/generic-confirm/html.hbs new file mode 100644 index 0000000000..2411b9831c --- /dev/null +++ b/src/sunstone/public/app/utils/dialogs/generic-confirm/html.hbs @@ -0,0 +1,18 @@ +
+
+

+ {{tr "Confirm"}} +
+

+
+
+
{{tr "You have to confirm this action."}}
+
+
{{tr "Do you want to proceed?"}}
+
+
+ +
+ × +
+
\ No newline at end of file