Project

General

Profile

1
/**
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
                        var oRecord = $("td#" + 'id_' + iRecordId);
27
                        switch(oElement.attr("src")){
28
                            case News.ThemeUrl + 'img/24' +"/status_1.png": var action = "0"; break;
29
                            case News.ThemeUrl + 'img/24' +"/status_0.png": var action = "1"; break;
30
                        }
31
                                // pregenerate the data string
32
/*
33
                        var sDataString = 'purpose=active_status&action=active_status'+'&MODULE='
34
                                        +aOpts.MODULE+'&DB_COLUMN='
35
                                        +aOpts.DB_COLUMN+'&iRecordId='
36
                                        +iRecordID;
37
*/
38
                        var sDataString = 'action=toggle_active_status&iRecordId='+iRecordId;
39
                        $.ajax({
40
                                url: News.AddonUrl +"ajax/ajax.php",
41
                                type: "POST",
42
                                dataType: 'json',
43
                                data: sDataString,
44
                                success: function(json_respond) {
45
                                    if(json_respond.success === true) {
46
/*
47
*/
48
                                        oRecord.attr("id", json_respond.sIdKey);
49
                                        oElement.attr("id", "active_"+ json_respond.sIdKey);
50
console.info(oRecord.attr);
51
                                        oElement.attr("src", News.ThemeUrl + 'img/24' +"/status_"+ action +".png");
52
//                                        oElement.animate({opacity: 1});
53
                                    } else {
54
                                            oRecord.attr("id", json_respond.sIdKey);
55
                                            oElement.attr("id", "active_"+ json_respond.sIdKey);
56
                                            alert(json_respond.message);
57
                                    }
58
                                }
59
                        });
60

    
61
                });
62
        }
63
})(jQuery);
(2-2/2)