Subversion Repositories wpShopGermany4

Rev

Rev 6244 | 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;
7804 daniel 27
			if (typeof options.type == "format") opt['format'] = options.format;
28
			if (typeof options.type == "viewformat") opt['viewformat'] = options.viewformat;
29
			if (typeof options.type == "template") opt['template'] = options.template;
5690 daniel 30
 
5911 daniel 31
			if (options.type == "select" && Array.isArray(options.data))
5896 daniel 32
			{
5911 daniel 33
 
34
				var value = "0";
5896 daniel 35
				var strValue = jQuery(this).html();
36
 
37
				for (var i in options.data)
38
				{
5911 daniel 39
 
40
					if (options.data[i].text == strValue) value = options.data[i].value;
5896 daniel 41
 
42
				}
43
 
44
				opt.source = options.data;
5911 daniel 45
                opt.type = 'select';
46
                opt.value = value;
5896 daniel 47
 
5911 daniel 48
			}
5720 daniel 49
            else if (options.type == 'multiarray')
50
            {
51
 
52
                var ar = [];
53
                var arData = jQuery.parseJSON(options.data);
5911 daniel 54
				var strValue = jQuery(this).html();
5720 daniel 55
 
56
                for (var i in arData)
57
                {
58
 
59
                    objData = { 'text': arData[i].name, 'children': [] };
60
 
61
                    for (var j in arData[i]['fields'])
62
                    {
63
 
64
                        objData['children'].push( { 'value': j, 'text': arData[i]['fields'][j] } );
65
 
5911 daniel 66
						if (arData[i]['fields'][j] == strValue) value = j;
67
 
5720 daniel 68
                    }
69
 
70
                    ar.push(objData);
71
 
72
                }
73
 
74
                opt.source = ar;
75
                opt.type = 'select';
6148 hartmut 76
				opt.value = value; //j;
5720 daniel 77
 
5489 daniel 78
			}
6244 daniel 79
			else if (options.type == 'checklist')
80
			{
81
 
82
				opt.type = 'checklist';
83
				opt.source = [];
84
				opt.value = options.value;
85
 
86
				for (var i in options.data)
87
				{
88
 
89
					opt.source.push( { value: i, text: options.data[i] } );
90
 
91
				}
92
 
93
			}
5489 daniel 94
			else
95
			{
5720 daniel 96
 
5489 daniel 97
				opt.display = function(value, sourceData) {
98
 
99
					jQuery(this).html(sourceData);
100
 
101
				};
102
 
6244 daniel 103
			}
5683 daniel 104
 
105
            if (typeof options.callback == "function") opt.success = options.callback;
5489 daniel 106
 
107
			jQuery(this).editable(opt);
108
 
5439 daniel 109
		} );
110
 
111
	}