Skip to content

Commit ac2aa3c

Browse files
committed
Dmitry M. created event.js model
1 parent a0c6072 commit ac2aa3c

23 files changed

+329
-726
lines changed

web/js/events.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Init kinda namespace object
2+
var VE = { // Vesta Events object
3+
core: {}, // core functions
4+
callbacks: { // events callback functions
5+
click: {},
6+
mouseover: {},
7+
mouseout: {},
8+
keypress: {}
9+
},
10+
helpers: {}, // simple handy methods
11+
tmp: {}
12+
};
13+
14+
/*
15+
* Main method that invokes further event processing
16+
* @param root is root HTML DOM element that. Pass HTML DOM Element or css selector
17+
* @param event_type (eg: click, mouseover etc..)
18+
*/
19+
VE.core.register = function(root, event_type) {
20+
var root = !root ? 'body' : root; // if elm is not passed just bind events to body DOM Element
21+
var event_type = !event_type ? 'click' : event_type; // set event type to "click" by default
22+
$(root).bind(event_type, function(evt) {
23+
var elm = $(evt.target);
24+
VE.core.dispatch(evt, elm, event_type); // dispatch captured event
25+
});
26+
}
27+
28+
/*
29+
* Dispatch event that was previously registered
30+
* @param evt related event object
31+
* @param elm that was catched
32+
* @param event_type (eg: click, mouseover etc..)
33+
*/
34+
VE.core.dispatch = function(evt, elm, event_type) {
35+
if ('undefined' == typeof VE.callbacks[event_type]) {
36+
return VE.helpers.warn('There is no corresponding object that should contain event callbacks for "'+event_type+'" event type');
37+
}
38+
// get class of element
39+
var classes = $(elm).attr('class');
40+
// if no classes are attached, then just stop any further processings
41+
if (!classes) {
42+
return; // no classes assigned
43+
}
44+
// split the classes and check if it related to function
45+
$(classes.split(/\s/)).each(function(i, key) {
46+
VE.callbacks[event_type][key] && VE.callbacks[event_type][key](evt, elm);
47+
});
48+
}
49+
50+
//
51+
// CALLBACKS
52+
//
53+
54+
55+
56+
/*
57+
* Suspend action
58+
*/
59+
VE.callbacks.click.do_suspend = function(evt, elm) {
60+
var ref = elm.hasClass('data-controls') ? elm : elm.parents('.data-controls');
61+
var url = $('input[name="suspend_url"]', ref).val();
62+
var dialog_elm = ref.find('.confirmation-text-suspention');
63+
VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm SUSPEND', url);
64+
}
65+
66+
/*
67+
* Unsuspend action
68+
*/
69+
VE.callbacks.click.do_unsuspend = function(evt, elm) {
70+
var ref = elm.hasClass('data-controls') ? elm : elm.parents('.data-controls');
71+
var url = $('input[name="unsuspend_url"]', ref).val();
72+
var dialog_elm = ref.find('.confirmation-text-suspention');
73+
VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm UNSUSPEND', url);
74+
}
75+
76+
/*
77+
* Delete action
78+
*/
79+
VE.callbacks.click.do_delete = function(evt, elm) {
80+
var ref = elm.hasClass('data-controls') ? elm : elm.parents('.data-controls');
81+
var url = $('input[name="delete_url"]', ref).val();
82+
var dialog_elm = ref.find('.confirmation-text-delete');
83+
VE.helpers.createConfirmationDialog(dialog_elm, 'Confirm DELETE', url);
84+
}
85+
86+
87+
/*
88+
* Create dialog box on the fly
89+
* @param elm Element which contains the dialog contents
90+
* @param dialog_title
91+
* @param confirmed_location_url URL that will be redirected to if user hit "OK"
92+
* @param custom_config Custom configuration parameters passed to dialog initialization (optional)
93+
*/
94+
VE.helpers.createConfirmationDialog = function(elm, dialog_title, confirmed_location_url, custom_config) {
95+
var custom_config = !custom_config ? {} : custom_config;
96+
var config = {
97+
modal: true,
98+
autoOpen: true,
99+
width: 360,
100+
title: dialog_title,
101+
close: function() {
102+
$(this).dialog("destroy");
103+
},
104+
buttons: {
105+
"Ok": function(event, ui) {
106+
location.href = confirmed_location_url;
107+
},
108+
"Cancel": function() {
109+
$(this).dialog("close");
110+
$(this).dialog("destroy");
111+
}
112+
}
113+
}
114+
config = $.extend(config, custom_config);
115+
var reference_copied = $(elm).clone();
116+
$(reference_copied).dialog(config);
117+
}
118+
119+
/*
120+
* Simple debug output
121+
*/
122+
VE.helpers.warn = function(msg) {
123+
alert('WARNING: ' + msg);
124+
}

web/templates/admin/list_backup.html

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -44,46 +44,6 @@
4444
if (!empty($data[$key]['DB'])) $db = 'yes ¨';
4545
?>
4646

47-
<script type="text/javascript">
48-
$(function(){
49-
$('#restore_dialog_<?php echo "$i" ?>').dialog({
50-
modal: true,
51-
autoOpen: false,
52-
width: 360,
53-
buttons: {
54-
"Ok": function(event, ui) {
55-
$(this).dialog("close");
56-
},
57-
"Cancel": function() {
58-
$(this).dialog("close");
59-
}
60-
}
61-
});
62-
$('#restore_link_<?php echo "$i" ?>').click(function(){
63-
$('#restore_dialog_<?php echo "$i" ?>').dialog('open');
64-
return false;
65-
});
66-
67-
$('#delete_dialog_<?php echo "$i" ?>').dialog({
68-
modal: true,
69-
autoOpen: false,
70-
width: 360,
71-
buttons: {
72-
"Ok": function(event, ui) {
73-
location.href = '/delete/backup/?backup=<?php echo "$key" ?>';
74-
},
75-
"Cancel": function() {
76-
$(this).dialog("close");
77-
}
78-
}
79-
});
80-
$('#delete_link_<?php echo "$i" ?>').click(function(){
81-
$('#delete_dialog_<?php echo "$i" ?>').dialog('open');
82-
return false;
83-
});
84-
});
85-
</script>
86-
8747
<tr class="data-row">
8848
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
8949
<table class="data-col1">
@@ -96,19 +56,14 @@
9656
<table width="830px">
9757
<tr>
9858
<td></td>
99-
<td class="data-controls" width="80px"><img src="/images/download.png" width="8px" height="8px"><a href="/download/backup/?backup=<?php echo $key ?>" target="_blank"> download</a></td>
100-
<td class="data-controls" width="80px">
101-
<img src="/images/restore.png" width="6px" height="8px">
102-
<a href="#" id="restore_link_<?php echo "$i"?>"> restore</a>
103-
<div id="restore_dialog_<?php echo "$i" ?>" title="Confirmation">
104-
<p class="counter-value">Are you sure you want to restore <b><?php echo "$key" ?></b> backup?</p>
105-
</div>
106-
</td>
107-
<td class="data-controls" width="70px">
108-
<img src="/images/delete.png" width="7px" height="7px">
109-
<a href="#" id="delete_link_<?php echo $i ?>"> delete</a>
110-
<div id="delete_dialog_<?php echo $i ?>" title="Confirmation">
111-
<p class="counter-value">Are you sure you want to delete <b><?php echo "$key" ?></b> backup?</p>
59+
<td class="data-controls" width="80px"><a href="/download/backup/?backup=<?php echo $key ?>" target="_blank"><img src="/images/download.png" width="8px" height="8px"> download</a></td>
60+
<td class="data-controls" width="80px"><a href="#" id="restore_link_<?php echo "$i"?>"><img src="/images/restore.png" width="6px" height="8px"> restore</a></td>
61+
<td class="data-controls do_delete" width="70px">
62+
<img src="/images/delete.png" width="7px" height="7px" class="do_delete">
63+
<a id="delete_link_<?php echo $i ?>" class="do_delete"> delete</a>
64+
<input type="hidden" name="delete_url" value="/delete/backup/?backup=<?php echo "$key" ?>" />
65+
<div id="delete_dialog_<?php echo $i ?>" class="confirmation-text-delete hidden" title="Confirmation">
66+
<p class="counter-value">Are you sure you want to delete <b><?php echo "$key" ?></b> backup ?</p>
11267
</div>
11368
</td>
11469
</tr>

web/templates/admin/list_cron.html

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -44,44 +44,6 @@
4444
?>
4545

4646
<tr class="data-row">
47-
<script type="text/javascript">
48-
$(function(){
49-
$('#<?php echo $spnd_action ?>_dialog_<?php echo "$i" ?>').dialog({
50-
modal: true,
51-
autoOpen: false,
52-
width: 360,
53-
buttons: {
54-
"Ok": function(event, ui) {
55-
location.href = '/<?php echo $spnd_action ?>/cron/?job=<?php echo $data[$key]['JOB']; ?>';
56-
},
57-
"Cancel": function() {
58-
$(this).dialog("close");
59-
}
60-
}
61-
});
62-
$('#<?php echo $spnd_action ?>_link_<?php echo "$i" ?>').click(function(){
63-
$('#<?php echo $spnd_action ?>_dialog_<?php echo "$i" ?>').dialog('open');
64-
return false;
65-
});
66-
$('#delete_dialog_<?php echo "$i" ?>').dialog({
67-
modal: true,
68-
autoOpen: false,
69-
width: 360,
70-
buttons: {
71-
"Ok": function(event, ui) {
72-
location.href = '/delete/cron/?job=<?php echo $data[$key]['JOB']; ?>';
73-
},
74-
"Cancel": function() {
75-
$(this).dialog("close");
76-
}
77-
}
78-
});
79-
$('#delete_link_<?php echo "$i" ?>').click(function(){
80-
$('#delete_dialog_<?php echo "$i" ?>').dialog('open');
81-
return false;
82-
});
83-
});
84-
</script>
8547
<td class="data-dotted" style="padding: 0px 10px 0px 0px" width="150">
8648
<table class="data-col1">
8749
<tr><td style="padding: 18 0 4 18;"><input type="checkbox" name="job[]" value="<?php echo $data[$key]['JOB'] ?>" ></td></tr>
@@ -93,18 +55,20 @@
9355
<table width="830px">
9456
<tr>
9557
<td></td>
96-
<td class="data-controls" width="50px"><img src="/images/edit.png" width="8px" height="8px"><a href="/edit/cron/?job=<?php echo $data[$key]['JOB'] ?>"> edit</a></td>
97-
<td class="data-controls" width="80px">
98-
<img src="/images/suspend.png" width="7px" height="8px">
99-
<a href="#" id="<?php echo $spnd_action ?>_link_<?php echo "$i" ?>"> <?php echo $spnd_action ?></a>
100-
<div id="<?php echo $spnd_action ?>_dialog_<?php echo "$i" ?>" title="Confirmation">
101-
<p class="counter-value">Are you sure you want to <?php echo $spnd_action ?> cron job?</p>
58+
<td class="data-controls" width="50px"><a href="/edit/cron/?job=<?php echo $data[$key]['JOB'] ?>"><img src="/images/edit.png" width="8px" height="8px"> edit</a></td>
59+
<td class="data-controls do_<?php echo $spnd_action ?>" width="80px">
60+
<img src="/images/suspend.png" width="7px" height="8px" class="do_<?php echo $spnd_action ?>">
61+
<a id="<?php echo $spnd_action ?>_link_<?php echo $i ?>" class="do_<?php echo $spnd_action ?>"> <?php echo $spnd_action ?></a>
62+
<input type="hidden" name="<?php echo $spnd_action ?>_url" value="/<?php echo $spnd_action ?>/cron/?job=<?php echo $data[$key]['JOB']; ?>" />
63+
<div id="<?php echo $spnd_action ?>_dialog_<?php echo $i ?>" class="confirmation-text-suspention hidden" title="Confirmation">
64+
<p class="counter-value">Are you sure you want to <?php echo $spnd_action ?> cron job?/p>
10265
</div>
10366
</td>
104-
<td class="data-controls" width="70px">
105-
<img src="/images/delete.png" width="7px" height="7px">
106-
<a href="#" id="delete_link_<?php echo $i ?>"> delete</a>
107-
<div id="delete_dialog_<?php echo $i ?>" title="Confirmation">
67+
<td class="data-controls do_delete" width="70px">
68+
<img src="/images/delete.png" width="7px" height="7px" class="do_delete">
69+
<a id="delete_link_<?php echo $i ?>" class="do_delete"> delete</a>
70+
<input type="hidden" name="delete_url" value="/delete/cron/?job=<?php echo $data[$key]['JOB']; ?>" />
71+
<div id="delete_dialog_<?php echo $i ?>" class="confirmation-text-delete hidden" title="Confirmation">
10872
<p class="counter-value">Are you sure you want to delete cron job?</p>
10973
</div>
11074
</td>

0 commit comments

Comments
 (0)