Subversion Repositories wpShopGermany4

Rev

Rev 6148 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1067 daniel 1
 
5439 daniel 2
	/**
3
	 * Wrapper, um die Editierfunktion austauschbarer zu machen
4
	 */
5934 hartmut 5
	jQuery.fn.wpsg_editable = function(url, options) {
5439 daniel 6
 
7
		return this.each(function() {
8
 
5489 daniel 9
			var opt = {
5439 daniel 10
				'type': 'text',
11
				'url': url,
12
				'pk': 1,
13
				'ajaxOptions': {
14
					'type': 'post'
15
				},
16
				'params': options['submitdata'],
17
				'placeholder': wpsg_ajax.ie_placeholder,
18
				'emptytext': wpsg_ajax.ie_emptytext,
19
				'validate': function(value) {
20
 
5521 daniel 21
				    //if(jQuery.trim(value) == '') { return wpsg_ajax.ie_validate_empty; }
5439 daniel 22
 
5489 daniel 23
				}
24
			};
5690 daniel 25
 
26
            if (typeof options.type == "string") opt['type'] = options.type;
27
 
5911 daniel 28
			if (options.type == "select" && Array.isArray(options.data))
5896 daniel 29
			{
5911 daniel 30
 
31
				var value = "0";
5896 daniel 32
				var strValue = jQuery(this).html();
33
 
34
				for (var i in options.data)
35
				{
5911 daniel 36
 
37
					if (options.data[i].text == strValue) value = options.data[i].value;
5896 daniel 38
 
39
				}
40
 
41
				opt.source = options.data;
5911 daniel 42
                opt.type = 'select';
43
                opt.value = value;
5896 daniel 44
 
5911 daniel 45
			}
5720 daniel 46
            else if (options.type == 'multiarray')
47
            {
48
 
49
                var ar = [];
50
                var arData = jQuery.parseJSON(options.data);
5911 daniel 51
				var strValue = jQuery(this).html();
5720 daniel 52
 
53
                for (var i in arData)
54
                {
55
 
56
                    objData = { 'text': arData[i].name, 'children': [] };
57
 
58
                    for (var j in arData[i]['fields'])
59
                    {
60
 
61
                        objData['children'].push( { 'value': j, 'text': arData[i]['fields'][j] } );
62
 
5911 daniel 63
						if (arData[i]['fields'][j] == strValue) value = j;
64
 
5720 daniel 65
                    }
66
 
67
                    ar.push(objData);
68
 
69
                }
70
 
71
                opt.source = ar;
72
                opt.type = 'select';
6148 hartmut 73
				opt.value = value; //j;
5720 daniel 74
 
5489 daniel 75
			}
6244 daniel 76
			else if (options.type == 'checklist')
77
			{
78
 
79
				opt.type = 'checklist';
80
				opt.source = [];
81
				opt.value = options.value;
82
 
83
				for (var i in options.data)
84
				{
85
 
86
					opt.source.push( { value: i, text: options.data[i] } );
87
 
88
				}
89
 
90
			}
5489 daniel 91
			else
92
			{
5720 daniel 93
 
5489 daniel 94
				opt.display = function(value, sourceData) {
95
 
96
					jQuery(this).html(sourceData);
97
 
98
				};
99
 
6244 daniel 100
			}
5683 daniel 101
 
102
            if (typeof options.callback == "function") opt.success = options.callback;
5489 daniel 103
 
104
			jQuery(this).editable(opt);
105
 
5439 daniel 106
		} );
107
 
108
	}