diff --git a/src/sunstone/public/app/app.js b/src/sunstone/public/app/app.js index 985fe81570..fcbdbf054f 100644 --- a/src/sunstone/public/app/app.js +++ b/src/sunstone/public/app/app.js @@ -43,11 +43,12 @@ var Websocket = require("utils/websocket"); var FireedgeValidator = require("utils/fireedge-validator") var _commonDialogs = [ -require('utils/dialogs/confirm'), -require('utils/dialogs/confirm-with-select'), -require('utils/dialogs/generic-confirm'), -require('utils/dialogs/clusters'), -require('utils/dialogs/overcommit') + require('utils/dialogs/confirm'), + require('utils/dialogs/confirm-with-select'), + require('utils/dialogs/generic-confirm'), + require('utils/dialogs/clusters'), + require('utils/dialogs/overcommit'), + require('utils/dialogs/leases') ] diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create.js index abfe609682..cea850d4f3 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create.js @@ -188,7 +188,7 @@ define(function(require) { var objLeases = $.extend(true, {}, that); objLeases.resource = "template"; objLeases.__proto__ = FormPanel.prototype; - Leases.actions(objLeases,"","", function(){ + Leases.actions(objLeases, "", "", function(){ sched_actions_events(context); }); diff --git a/src/sunstone/public/app/utils/dialogs/leases.js b/src/sunstone/public/app/utils/dialogs/leases.js new file mode 100644 index 0000000000..06f5d3c4ba --- /dev/null +++ b/src/sunstone/public/app/utils/dialogs/leases.js @@ -0,0 +1,152 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require("utils/dialogs/dialog"); + var TemplateHTML = require("hbs!./leases/html"); + var Sunstone = require("sunstone"); + var Locale = require("utils/locale"); + + /* + CONSTANTS + */ + + var DIALOG_ID = require("./leases/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.headerTabId : Optional, tabId for the subheader resource ids + * - params.body : Optional, html string + * - params.question : Optional, html string + * - params.buttons : Optional, html string for the button. + * Can be an array for multiple options + * - params.submit : Mandatory, function to call if user confirms + * If buttons is an array, it must be an array + * of the same size + */ + function _setParams(params) { + this.params = params; + + if (this.params.buttons != undefined && !$.isArray(this.params.buttons)){ + this.params.buttons = [this.params.buttons]; + } + + if (this.params.submit != undefined && !$.isArray(this.params.submit)){ + this.params.submit = [this.params.submit]; + } + } + + function _setup(context) { + var that = this; + + $(context).keypress(function (e) { + if (e.which == 13 || e.keyCode == 13) { + $("#" + DIALOG_ID + "Form", context).submit(); + return false; + } else { + return true; + } + }); + + $("#" + DIALOG_ID + "Form", context).submit(function(e) { + // With more than one button, skip + if (that.params.buttons != undefined && that.params.buttons.length > 1){ + e.preventDefault(); + return false; + } + + Sunstone.getDialog(DIALOG_ID).hide(); + + if (that.params.submit != undefined){ + that.params.submit[0](this); + } + + return false; + }); + + $(context).on("click", ".custom_submit", function(){ + var index = $(this).attr("submit"); + that.params.submit[index](); + + Sunstone.getDialog(DIALOG_ID).hide(); + return false; + }); + + return false; + } + + function _onShow(context) { + if (this.params.header != undefined){ + $("#header", context).html(this.params.header); + } + + if (this.params.body != undefined){ + $("#body", context).html(this.params.body); + } + + if (this.params.question != undefined){ + $("#question", context).html(this.params.question); + } + + if (this.params.buttons != undefined){ + var html = ""; + + $.each(this.params.buttons, function(i, text){ + html += ""; + }); + + $(".form_buttons", context).html(html); + } + + if (this.params.headerTabId != undefined){ + this.setNames( {tabId: this.params.headerTabId} ); + } + + return false; + } +}); diff --git a/src/sunstone/public/app/utils/dialogs/leases/dialogId.js b/src/sunstone/public/app/utils/dialogs/leases/dialogId.js new file mode 100644 index 0000000000..1aa23b5e99 --- /dev/null +++ b/src/sunstone/public/app/utils/dialogs/leases/dialogId.js @@ -0,0 +1,19 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + return "addLeasesDialog"; +}); diff --git a/src/sunstone/public/app/utils/dialogs/leases/html.hbs b/src/sunstone/public/app/utils/dialogs/leases/html.hbs new file mode 100644 index 0000000000..8668da4148 --- /dev/null +++ b/src/sunstone/public/app/utils/dialogs/leases/html.hbs @@ -0,0 +1,37 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2020, OpenNebula Project, OpenNebula Systems }} +{{! }} +{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }} +{{! not use this file except in compliance with the License. You may obtain }} +{{! a copy of the License at }} +{{! }} +{{! http://www.apache.org/licenses/LICENSE-2.0 }} +{{! }} +{{! Unless required by applicable law or agreed to in writing, software }} +{{! distributed under the License is distributed on an "AS IS" BASIS, }} +{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }} +{{! See the License for the specific language governing permissions and }} +{{! limitations under the License. }} +{{! -------------------------------------------------------------------------- }} + +