1 | /* |
||
2 | * @copyright 2019 Christoph Wurst <[email protected]> |
||
3 | * |
||
4 | * @author 2019 Christoph Wurst <[email protected]> |
||
5 | * |
||
6 | * @license GNU AGPL version 3 or any later version |
||
7 | * |
||
8 | * This program is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU Affero General Public License as |
||
10 | * published by the Free Software Foundation, either version 3 of the |
||
11 | * License, or (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU Affero General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Affero General Public License |
||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | |||
22 | import $ from 'jquery' |
||
0 ignored issues
–
show
|
|||
23 | import {filePath} from './routing' |
||
0 ignored issues
–
show
'import' is only available in ES6 (use 'esversion: 6').
Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code. Further Reading:
Loading history...
|
|||
24 | |||
25 | /** |
||
26 | * Opens a popup with the setting for an app. |
||
27 | * @param {string} appid The ID of the app e.g. 'calendar', 'contacts' or 'files'. |
||
28 | * @param {boolean|string} loadJS If true 'js/settings.js' is loaded. If it's a string |
||
29 | * it will attempt to load a script by that name in the 'js' directory. |
||
30 | * @param {boolean} [cache] If true the javascript file won't be forced refreshed. Defaults to true. |
||
31 | * @param {string} [scriptName] The name of the PHP file to load. Defaults to 'settings.php' in |
||
32 | * the root of the app directory hierarchy. |
||
33 | * |
||
34 | * @deprecated 17.0.0 this method is unused and will be removed with Nextcloud 18 |
||
35 | */ |
||
36 | export const appSettings = args => { |
||
0 ignored issues
–
show
'export' is only available in ES6 (use 'esversion: 6').
Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code. Further Reading:
Loading history...
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').
Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code. Further Reading:
Loading history...
|
|||
37 | console.warn('OC.appSettings is deprecated and will be removed with Nextcloud 18') |
||
38 | |||
39 | if (typeof args === 'undefined' || typeof args.appid === 'undefined') { |
||
40 | throw { |
||
41 | name: 'MissingParameter', |
||
42 | message: 'The parameter appid is missing' |
||
43 | } |
||
44 | } |
||
45 | var props = {scriptName: 'settings.php', cache: true} |
||
46 | $.extend(props, args) |
||
47 | var settings = $('#appsettings') |
||
48 | if (settings.length === 0) { |
||
49 | throw { |
||
50 | name: 'MissingDOMElement', |
||
51 | message: 'There has be be an element with id "appsettings" for the popup to show.' |
||
52 | } |
||
53 | } |
||
54 | var popup = $('#appsettings_popup') |
||
55 | if (popup.length === 0) { |
||
56 | $('body').prepend('<div class="popup hidden" id="appsettings_popup"></div>') |
||
57 | popup = $('#appsettings_popup') |
||
58 | popup.addClass(settings.hasClass('topright') ? 'topright' : 'bottomleft') |
||
59 | } |
||
60 | if (popup.is(':visible')) { |
||
61 | popup.hide().remove() |
||
62 | } else { |
||
63 | const arrowclass = settings.hasClass('topright') ? 'up' : 'left' |
||
0 ignored issues
–
show
|
|||
64 | $.get(filePath(props.appid, '', props.scriptName), function (data) { |
||
65 | popup.html(data).ready(function () { |
||
66 | popup.prepend('<span class="arrow ' + arrowclass + '"></span><h2>' + t('core', 'Settings') + '</h2><a class="close"></a>').show() |
||
67 | popup.find('.close').bind('click', function () { |
||
68 | popup.remove() |
||
69 | }) |
||
70 | if (typeof props.loadJS !== 'undefined') { |
||
71 | var scriptname |
||
72 | if (props.loadJS === true) { |
||
73 | scriptname = 'settings.js' |
||
74 | } else if (typeof props.loadJS === 'string') { |
||
75 | scriptname = props.loadJS |
||
76 | } else { |
||
77 | throw { |
||
78 | name: 'InvalidParameter', |
||
79 | message: 'The "loadJS" parameter must be either boolean or a string.' |
||
80 | } |
||
81 | } |
||
82 | if (props.cache) { |
||
83 | $.ajaxSetup({cache: true}) |
||
84 | } |
||
85 | $.getScript(filePath(props.appid, 'js', scriptname)) |
||
86 | .fail(function (jqxhr, settings, e) { |
||
87 | throw e |
||
88 | }) |
||
89 | } |
||
90 | }).show() |
||
91 | }, 'html') |
||
92 | } |
||
93 | } |
||
94 |
Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.
Further Reading: