This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
107 lines (95 loc) · 3.43 KB
/
common.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
// Console object name
var EXT_CONSOLE_DIV = "DynAdminExtentionConsole";
var EXT_CONSOLE_DIV_ID = "#" + EXT_CONSOLE_DIV;
var EXT_CONSOLE_STATUS_DIV = 'custom_status_div';
var EXT_CONSOLE_STATUS_DIV_ID = '#' + EXT_CONSOLE_STATUS_DIV;
var BUTTON_STYLE = 'margin:2px;padding:2px;';
var BUTTON_BORDER_RED = 'border: 2px solid red;';
var BUTTON_BORDER_GREEN = 'border: 2px solid green;';
//TODO for now it forks only for boolean properties
function addChangePropertyValueButton(buttonName, propertyName){
var button = createButton(buttonName, function(){
var propertyObject = getPropertyValueObject(propertyName);
var currentValue = $.parseJSON(propertyObject.text());
$.ajax({
type: 'POST',
url: window.location.href,
data: {'propertyName':propertyName,'newValue':!currentValue,'change':'Change Value'},
success: function (data) {
propertyObject.text(!currentValue);
button.setAttribute('style', getButtonStyleOfBooleanTrigger(!currentValue));
}
})
}
);
button.setAttribute('style', getButtonStyleOfBooleanTrigger(getBooleanPropertyValue(propertyName)));
$(EXT_CONSOLE_DIV_ID).append(button);
}
function getPropertyValueObject(propertyName){
return getPropertyObject(propertyName).closest('td').next().find('span');
}
function getPropertyObject(propertyName){
return $('a:contains("' + propertyName + '")').first();
}
function getButtonStyleOfBooleanTrigger(value){
return BUTTON_STYLE + (value ? BUTTON_BORDER_GREEN : BUTTON_BORDER_RED);
}
function getBooleanPropertyValue(propertyName){
return $.parseJSON(getPropertyValue(propertyName));
}
function getPropertyValue(propertyName){
return getPropertyObject(propertyName).closest('td').next().find('span').text();
}
function clearStatusDiv(name){
$('div #custom_' + name).html('');
}
function addCacheInvalidationButton(className, methodName){
var className = $('a:contains("' + className + '")');
if (className.length > 0){
$(EXT_CONSOLE_DIV_ID).append('<br>');
$(EXT_CONSOLE_DIV_ID).append('Caches:');
var invalCacheButName = 'Invalidate';
var successFunc = function(){
//console.log('Success');
var statusDiv = $(EXT_CONSOLE_STATUS_DIV_ID);
statusDiv.html('OK');
setTimeout(function (){statusDiv.html('');}, 10000);
};
var errorFunc = function(){
//console.log('Error');
var statusDiv = $(EXT_CONSOLE_STATUS_DIV_ID);
statusDiv.html('ERROR');
setTimeout(function (){statusDiv.html('');}, 10000);
};
var startFunction = function(){
//console.log('Start');
var statusDiv = $(EXT_CONSOLE_STATUS_DIV_ID);
statusDiv.html('Pending...');
}
addMethodInvocationButton(invalCacheButName, methodName, successFunc, errorFunc, startFunction);
}
}
function addMethodInvocationButton(buttonName, methodName, successFunc, errorFunc, startFunction){
var button = createButton(buttonName, function(){
startFunction();
$.ajax({
type: 'POST',
url: window.location.href,
data: {'invokeMethod':methodName,'submit':'Invoke Method'},
success: successFunc,
error: errorFunc
})
}
);
button.setAttribute('style', 'margin:2px;');
$(EXT_CONSOLE_DIV_ID).append(button);
}
function addPropertyRedirectButton(buttonName, propertyName){
var button = createButton(buttonName, function(){
window.location.href = window.location.href + '?propertyName=' + propertyName;
}
);
button.setAttribute('style', 'margin:2px;');
$(EXT_CONSOLE_DIV_ID).append('<br>');
$(EXT_CONSOLE_DIV_ID).append(button);
}