/* global alert */ /* * @copyright 2019 Christoph Wurst * * @author 2019 Christoph Wurst * * @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, // used to name each dialog dialogsCounter: 0, /** * displays alert dialog * @param text content of dialog * @param title dialog title * @param callback which will be triggered when user presses OK * @param 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 text content of dialog * @param title dialog title * @param callback which will be triggered when user presses OK * @param 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 text content of dialog * @param title dialog title * @param callback which will be triggered when user presses YES or NO * (true or false would be passed to callback respectively) * @param modal make the dialog modal */ confirm: function (text, title, callback, modal) { return this.message( text, title, 'notice', Dialogs.YES_NO_BUTTONS, callback, modal ); }, /** * displays confirmation dialog * @param text content of dialog * @param title dialog title * @param callback which will be triggered when user presses YES or NO * (true or false would be passed to callback respectively) * @param modal make the dialog modal */ confirmHtml: function (text, title, callback, modal) { return this.message( text, title, 'notice', Dialogs.YES_NO_BUTTONS, callback, modal, true ); }, /** * displays prompt dialog * @param text content of dialog * @param title dialog title * @param callback which will be triggered when user presses YES or NO * (true or false would be passed to callback respectively) * @param modal make the dialog modal * @param name name of the input field * @param password whether the input should be a password input */ 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 = $('