1 |
2
|
Manuela
|
/**
|
2 |
|
|
* AJAX
|
3 |
|
|
* Plugin to delete Records from a given table without a new page load (no reload)
|
4 |
|
|
*/
|
5 |
|
|
// Building a jQuery Plugin
|
6 |
|
|
// using the Tutorial: http://www.learningjquery.com/2007/10/a-plugin-development-pattern
|
7 |
|
|
// plugin definition
|
8 |
|
|
/*
|
9 |
|
|
ajaxActiveStatus OPTIONS
|
10 |
|
|
=====================================================================================
|
11 |
|
|
MODULE = 'modulename', // (string)
|
12 |
|
|
DB_RECORD_TABLE: 'modulename_table', // (string)
|
13 |
|
|
DB_COLUMN: 'item_id', // (string) the key column you will use as reference
|
14 |
|
|
sFTAN: '' // (string) FTAN
|
15 |
|
|
*/
|
16 |
|
|
|
17 |
|
|
(function($) {
|
18 |
|
|
$.fn.ajaxActiveStatus = function(options) {
|
19 |
|
|
var aOpts = $.extend({}, $.fn.ajaxActiveStatus.defaults, options);
|
20 |
|
|
//console.info(aOpts);
|
21 |
|
|
$(this).find('a').removeAttr("href").css('cursor', 'pointer');
|
22 |
|
|
$(this).click(function() {
|
23 |
|
|
var oLink = $(this).find('a');
|
24 |
|
|
var oElement = $(this).find('img');
|
25 |
|
|
var iRecordId = oElement.attr("id").substring(7);
|
26 |
|
|
console.info(iRecordId);
|
27 |
|
|
var oRecord = $("td#" + 'id_' + iRecordId);
|
28 |
|
|
switch(oElement.attr("src")){
|
29 |
|
|
case Droplet.ThemeUrl + 'img/24' +"/status_1.png": var action = "0"; break;
|
30 |
|
|
case Droplet.ThemeUrl + 'img/24' +"/status_0.png": var action = "1"; break;
|
31 |
|
|
}
|
32 |
|
|
console.info(oRecord);
|
33 |
|
|
// pregenerate the data string
|
34 |
|
|
/*
|
35 |
|
|
var sDataString = 'purpose=active_status&action=active_status'+'&MODULE='
|
36 |
|
|
+aOpts.MODULE+'&DB_COLUMN='
|
37 |
|
|
+aOpts.DB_COLUMN+'&iRecordID='
|
38 |
|
|
+iRecordID;
|
39 |
|
|
*/
|
40 |
|
|
var sDataString = 'action=toggle_active_status&iRecordId='+iRecordId;
|
41 |
|
|
$.ajax({
|
42 |
|
|
url: Droplet.AddonUrl +"ajax/ajax.php",
|
43 |
|
|
type: "POST",
|
44 |
|
|
dataType: 'json',
|
45 |
|
|
data: sDataString,
|
46 |
|
|
success: function(json_respond) {
|
47 |
|
|
if(json_respond.success === true) {
|
48 |
|
|
/*
|
49 |
|
|
*/
|
50 |
|
|
oRecord.attr("id", json_respond.sIdKey);
|
51 |
|
|
oElement.attr("id", "active_"+ json_respond.sIdKey);
|
52 |
|
|
console.info(oRecord.attr);
|
53 |
|
|
oElement.attr("src", Droplet.ThemeUrl + 'img/24' +"/status_"+ action +".png");
|
54 |
|
|
// oElement.animate({opacity: 1});
|
55 |
|
|
} else {
|
56 |
|
|
oRecord.attr("id", json_respond.sIdKey);
|
57 |
|
|
oElement.attr("id", "active_"+ json_respond.sIdKey);
|
58 |
|
|
alert(json_respond.message);
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
});
|
62 |
|
|
|
63 |
|
|
});
|
64 |
|
|
}
|
65 |
|
|
})(jQuery);
|