/* eslint-disable */ /* * @copyright 2019 Christoph Wurst * @copyright Copyright (c) 2019 Gary Kim * * @author 2019 Christoph Wurst * @author Gary Kim * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import _ from 'underscore' import $ from 'jquery' import OC from './index' import OCA from '../OCA/index' /** * this class to ease the usage of jquery dialogs */ const Dialogs = { // dialog button types YES_NO_BUTTONS: 70, OK_BUTTONS: 71, FILEPICKER_TYPE_CHOOSE: 1, FILEPICKER_TYPE_MOVE: 2, FILEPICKER_TYPE_COPY: 3, FILEPICKER_TYPE_COPY_MOVE: 4, FILEPICKER_TYPE_CUSTOM: 5, // used to name each dialog dialogsCounter: 0, /** * displays alert dialog * @param {string} text content of dialog * @param {string} title dialog title * @param {function} callback which will be triggered when user presses OK * @param {boolean} [modal] make the dialog modal */ alert: function(text, title, callback, modal) { this.message( text, title, 'alert', Dialogs.OK_BUTTON, callback, modal ) }, /** * displays info dialog * @param {string} text content of dialog * @param {string} title dialog title * @param {function} callback which will be triggered when user presses OK * @param {boolean} [modal] make the dialog modal */ info: function(text, title, callback, modal) { this.message(text, title, 'info', Dialogs.OK_BUTTON, callback, modal) }, /** * displays confirmation dialog * @param {string} text content of dialog * @param {string} title dialog title * @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively) * @param {boolean} [modal] make the dialog modal * @returns {Promise} */ confirm: function(text, title, callback, modal) { return this.message( text, title, 'notice', Dialogs.YES_NO_BUTTONS, callback, modal ) }, /** * displays confirmation dialog * @param {string} text content of dialog * @param {string} title dialog title * @param {{type: Int, confirm: String, cancel: String, confirmClasses: String}} buttons text content of buttons * @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively) * @param {boolean} [modal] make the dialog modal * @returns {Promise} */ confirmDestructive: function(text, title, buttons, callback, modal) { return this.message( text, title, 'none', buttons, callback, modal === undefined ? true : modal ) }, /** * displays confirmation dialog * @param {string} text content of dialog * @param {string} title dialog title * @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively) * @param {boolean} [modal] make the dialog modal * @returns {Promise} */ confirmHtml: function(text, title, callback, modal) { return this.message( text, title, 'notice', Dialogs.YES_NO_BUTTONS, callback, modal, true ) }, /** * displays prompt dialog * @param {string} text content of dialog * @param {string} title dialog title * @param {function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively) * @param {boolean} [modal] make the dialog modal * @param {string} name name of the input field * @param {boolean} password whether the input should be a password input * @returns {Promise} */ prompt: function(text, title, callback, modal, name, password) { return $.when(this._getMessageTemplate()).then(function($tmpl) { var dialogName = 'oc-dialog-' + Dialogs.dialogsCounter + '-content' var dialogId = '#' + dialogName var $dlg = $tmpl.octemplate({ dialog_name: dialogName, title: title, message: text, type: 'notice' }) var input = $('') input.attr('type', password ? 'password' : 'text').attr('id', dialogName + '-input').attr('placeholder', name) var label = $('