-
Notifications
You must be signed in to change notification settings - Fork 13
/
bda.menu.js
executable file
·313 lines (258 loc) · 13.3 KB
/
bda.menu.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
try {
jQuery(document).ready(function() {
(function($) {
try {
var templates = {
};
var BDA_MENU = {
build: function() {
console.time("bdaMenu");
var $menuBar = $("<div id='menuBar'></div>").appendTo("body");
BDA_MENU.$menuBar = $menuBar;
BDA_MENU.createBugReportPanel($menuBar);
BDA_MENU.createBackupPanel($menuBar);
BDA_MENU.createConfigurationPanel($menuBar);
BDA_MENU.createWhatsnewPanel($menuBar);
BDA_MENU.createSearchBox($menuBar);
//generic bind so that new elems are automatically binded
$menuBar.on("click", ".menu", function(event) {
var $thisParent = $(this);
var $panel;
$('.menu').each(function() {
var $this = $(this);
$panel = $('#' + $this.attr('data-panel'));
if ($this.attr('id') != $thisParent.attr('id') && $panel.css('display') != "none") {
$panel.slideToggle();
rotateArrow($this.find(".menuArrow i"));
}
});
$panel = $('#' + $thisParent.attr('data-panel'));
$panel.slideToggle();
rotateArrow($thisParent.find(".menuArrow i"));
});
console.timeEnd("bdaMenu");
},
//--- Config Panel
createConfigurationPanel: function($menuBar) {
$("<div id='bdaConfig' class='menu' data-panel='bdaConfigPanel'></div>")
.appendTo($menuBar)
.html("<p>Configuration</p>" + "<div class='menuArrow'><i class='up fa fa-arrow-down'></i></div>");
var $bdaConfigPanel = $("<div id='bdaConfigPanel' class='menuPanel'></div>")
.appendTo("body")
.html("<p>I want to use the same BDA data on every domains : <input type='checkbox' id='" + BDA_STORAGE.GMValue_MonoInstance + "'>");
BDA_MENU.createCheckBoxConfig($bdaConfigPanel,{
name:'search_autocomplete',
description: 'Search AutoComplete',
message: '<p>Be aware of perfs impacts. Reload dyn/admin to take into account</p>'
});
BDA_MENU.createCheckBoxConfig($bdaConfigPanel,
{
description:'Display xmlDef as table by default',
name:'defaultOpenXmlDefAsTable'
});
BDA_MENU.createDefaultMethodsConfig($bdaConfigPanel);
BDA_MENU.createDataSourceFolderConfig($bdaConfigPanel);
$('#' + BDA_STORAGE.GMValue_MonoInstance).prop("checked", (GM_getValue(BDA_STORAGE.GMValue_MonoInstance) === true))
.click(function() {
var isMonoInstance = $(this).prop('checked');
console.log("Setting storage mode to mono-instance : " + isMonoInstance);
GM_setValue(BDA_STORAGE.GMValue_MonoInstance, isMonoInstance);
if (isMonoInstance)
GM_setValue(BDA_STORAGE.GMValue_Backup, JSON.stringify(BDA_STORAGE.getData()));
});
},
//--- Bug report panel
createBugReportPanel: function($menuBar) {
$("<div id='bdaBug' class='menu' data-panel='bdaBugPanel'></div>").appendTo($menuBar)
.html("<p>About</p>" + "<div class='menuArrow'><i class='up fa fa-arrow-down'></i></div>");
$("<div id='bdaBugPanel' class='menuPanel'></div>").appendTo("body")
.html("<p>How can I help and stay tuned ? " + "<br /><br /> Better Dyn Admin has a <a target='_blank' href='https://github.com/jc7447/BetterDynAdmin'>GitHub page</a>. <br>" + "Please report any bug in the <a target='_blank' href='https://github.com/jc7447/BetterDynAdmin/issues'>issues tracker</a>. Of course, you can also request new feature or suggest enhancement !" + "<br /><br /> <strong> BDA version " + GM_info.script.version + "</strong> </p>");
},
//--- what's new functions --------------------------------------------------------------------------
createWhatsnewPanel: function($menuBar) {
$("<div id='whatsnew' class='menu' data-panel='whatsnewPanel'></div>")
.appendTo($menuBar)
.html("<p>What's new</p>" + "<div class='menuArrow'><i class='up fa fa-arrow-down'></i></div>");
$("<div id='whatsnewPanel' class='menuPanel'></div>")
.appendTo("body")
.html("<p id='whatsnewContent'></p>");
$("#whatsnew").click(function() {
console.log("On click whats new");
if ($("#whatsnewPanel").css("display") === "none")
$("#whatsnewContent").html(GM_getResourceText("whatsnew"));
});
},
//--- backup panel functions ------------------------------------------------------------------------
createBackupPanel: function($menuBar) {
$("<div id='bdaBackup' class='menu' data-panel='bdaBackupPanel'></div>").appendTo($menuBar)
.html("<p>Backup</p>" + "<div class='menuArrow'><i class='up fa fa-arrow-down'></i></div>");
$("<div id='bdaBackupPanel' class='menuPanel'></div>").appendTo("body")
.html("<p>Why should I save Better Dyn Admin data ? " + "<br /><br /> Because BDA use javascript local storage. You will lose your favorite components and your stored queries if you clean your browser." + "<br /><br /><strong> Remember that you can also import your backup to a BDA in another domain !</strong> </p>" + "<textarea id='bdaData' placeholder='Paste your data here to restore it.'></textarea>" + "<button id='bdaDataBackup'>Backup</button>" + "<button id='bdaDataRestore'>Restore</button>");
$("#bdaDataBackup").click(function() {
var data = BDA_STORAGE.getData();
logTrace('bdaDataBackup ' + data);
copyToClipboard(JSON.stringify(data));
});
$("#bdaDataRestore").click(function() {
if (window.confirm("Sure ?")) {
var data = $("#bdaData").val().trim();
BDA_STORAGE.restoreData(data, true);
}
});
},
//--- Search
createSearchBox: function($menuBar) {
$searchBox = $("<div id='bdaSearch' class='menu' ></div>")
.appendTo($menuBar)
.html(
'<p>Search</p>' + '<form action="/dyn/admin/atg/dynamo/admin/en/cmpn-search.jhtml">' + '<input type="text" name="query" id="searchFieldBDA" placeholder="focus: ctrl+shift+f"></input> ' + '</form>'
);
try {
var autocomplete = BDA_STORAGE.getConfigurationValue('search_autocomplete');
autocomplete = (autocomplete == true) ? true : false;
if (autocomplete) {
$('#searchFieldBDA').bdaSearch({
'align': 'right'
});
}
} catch (e) {
console.error(e);
}
$(document).keypress(function(e) {
var moz = (e.which == 70 && e.ctrlKey && e.shiftKey ? 1 : 0);
var chrome = (e.which == 6 && e.ctrlKey && e.shiftKey ? 1 : 0);
if (moz || chrome) {
$('#searchFieldBDA').focus();
}
});
},
// advanced config
createCheckBoxConfig: function(parentPanel,inOptions) {
var options = $.extend(
{
name:null,
description:null,
message:''
},
inOptions);
var value = BDA_STORAGE.getConfigurationValue(options.name);
value = (value == true) ? true : false;
logTrace('value of {0} = {1}',name ,value);
var checked = value ? 'checked="true"' : '';
parentPanel.append('<p class="config">{0} : <input type="checkbox" id="{1}_config" {2}/></p>{3}'.format(options.description,options.name,checked,options.message));
$('#{0}_config'.format(options.name)).on('change', function() {
var val = $(this).is(':checked');
logTrace('save {0} {1} '.format( options.name, val));
BDA_STORAGE.storeConfiguration(options.name, val);
});
},
createDefaultMethodsConfig: function(parentPanel) {
var $config = $('<div id="advancedConfig"></div>');
$config.appendTo(parentPanel);
// Default methods
var savedMethods = BDA_STORAGE.getConfigurationValue('default_methods');
if (!savedMethods) {
savedMethods = "";
}
$config.append(
"<p>Default methods when bookmarking components:</p>" + "<textarea id='config-methods-data' class='' placeholder='List of methods names, comma separated'>" + savedMethods + "</textarea>"
);
//default methods
var $submitMethods = $('<button id="config-methods-submit">Save</button>')
.bind('click', function() {
var methods = $('#config-methods-data').val().trim();
var methodsArray = methods.replace(/ /g, '').split(",");
console.log('storing methods : ' + methodsArray);
BDA_STORAGE.storeConfiguration("default_methods", methodsArray);
});
$config.append($submitMethods);
// Default properties
var savedProperties = BDA_STORAGE.getConfigurationValue('default_properties');
if (!savedProperties) {
savedProperties = "";
}
$config.append(
"<p>Default properties when bookmarking components:</p>" + "<textarea id='config-properties-data' class='' placeholder='List of properties, comma separated'>" + savedProperties + "</textarea>"
);
var $submitProperties = $('<button id="config-properties-submit">Save</button>')
.bind('click', function() {
var properties = $('#config-properties-data').val().trim();
var propertiesArray = properties.replace(/ /g, '').split(",");
console.log('storing properties : ' + propertiesArray);
BDA_STORAGE.storeConfiguration("default_properties", propertiesArray);
});
$config.append($submitProperties);
var savedTags = BDA_STORAGE.getTags();
var tagAsString = "";
var index = 0;
var tagsSize = Object.keys(savedTags).length;
for (var key in savedTags) {
tagAsString += key;
if (index < tagsSize) {
tagAsString += ',';
}
index++;
}
$config.append(
"<p>Edit tags:</p>" + "<textarea id='config-tags-data' class='' placeholder='List of tags, comma separated'>" + tagAsString + "</textarea>"
);
var $submitTags = $('<button id="config-tags-submit">Save</button>')
.bind('click', function() {
var tagString = $('#config-tags-data').val();
var tags = BDA_TOOLBAR.buildTagsFromString(tagString, false);
console.log('storing tags : ' + JSON.stringify(tags));
BDA_TOOLBAR.editTags(tags);
BDA_TOOLBAR.reloadToolbar();
});
$config.append($submitTags);
},
createDataSourceFolderConfig: function(parentPanel) {
var $config = $('<div id="advancedConfig"></div>');
$config.appendTo(parentPanel);
// Default folders
var savedFolders = BDA_STORAGE.getConfigurationValue('data_source_folder');
if (!savedFolders) {
savedFolders = "";
}
$config.append(
"<p>Folders for JDBC data source :</p>" + "<textarea id='config-data-source-folders-data' class='' placeholder='List of folder path, comma separated'>" + savedFolders + "</textarea>"
);
//save folders
var $submitMethods = $('<button id="config-data-source-folders-submit">Save</button>')
.bind('click', function() {
var folders = $('#config-data-source-folders-data').val().trim();
var foldersArray = folders.replace(/ /g, '').split(",");
console.log('storing folders : ' + foldersArray);
BDA_STORAGE.storeConfiguration("data_source_folder", foldersArray);
});
$config.append($submitMethods);
},
createMenuElement: function($element) {
logTrace('createMenuElement');
logTrace($element);
$element.addClass('menu').appendTo(BDA_MENU.$menuBar);
},
};
var defaults = {};
var settings;
// Reference to BDA_STORAGE
var BDA_STORAGE;
$.fn.bdaMenu = function(options) {
console.log('Init plugin {0}'.format('bdaMenu'));
settings = $.extend({}, defaults, options);
BDA_STORAGE = $.fn.bdaStorage.getBdaStorage();
BDA_MENU.build();
return this;
};
$.fn.bdaAddMenuElem = function($elem) {
BDA_MENU.createMenuElement($elem);
return this;
};
} catch (e) {
console.log(e);
}
})(jQuery);
});
} catch (e) {
console.log(e);
}