/
dialog.uncompressed.js
115 lines (88 loc) · 2.93 KB
/
dialog.uncompressed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
(c)opyright 2017-2018 Michael Daum http://michaeldaumconsulting.com
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
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.
As per the GPL, removal of this notice is prohibited.
*/
/*eslint-disable no-console */
"use strict";
(function($) {
var defaults = {
"template": "metadata",
"debug": false
};
/* constructor **********************************************************/
function Dialog(opts) {
var self = this;
self.opts = $.extend({}, defaults, opts);
}
/* shortcut *************************************************************/
Dialog.load = function(opts) {
var dialog = new Dialog(opts);
return dialog.load();
};
/* logger ***************************************************************/
Dialog.prototype.log = function() {
var self = this, args;
if (!console || !self.opts.debug) {
return;
}
args = $.makeArray(arguments);
args.unshift("DIALOG:");
console.log.apply(console, args);
};
/* load *****************************************************************/
Dialog.prototype.load = function(params) {
var self = this,
opts = $.extend({}, self.opts, params),
$dialog = typeof(opts.id) === 'undefined'?undefined:$(opts.id),
data,
dfd = $.Deferred();
self.log("called load() opts=",opts);
function callback(elem) {
if (typeof(opts.init) === 'function') {
opts.init.call(elem);
}
}
if ($dialog && $dialog.length) {
$dialog.dialog("open");
$dialog.find("form").resetForm();
callback($dialog);
dfd.resolve($dialog);
} else {
data = $.extend({}, opts.data, {
name: opts.template,
expand: opts.expand,
topic: foswiki.getPreference("WEB")+"."+foswiki.getPreference("TOPIC")
});
$.ajax({
url: foswiki.getScriptUrl("rest", "RenderPlugin", "template"),
data: data,
dataType: 'html',
success: function(data) {
var $dialog = $(data);
$dialog.one("dialogopen", function() {
callback($dialog);
dfd.resolve($dialog);
});
$dialog.appendTo("body");
},
error: function(xhr, status, err) {
dfd.reject($dialog, status, err);
}
});
}
return dfd.promise();
};
// export
window.Dialog = Dialog;
})(jQuery);