summaryrefslogtreecommitdiff
path: root/views/js/editable.js
blob: 9717064c37d980a62b8612cafb96174d714cf167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

	/**
	 * Wrapper, um die Editierfunktion austauschbarer zu machen
	 */
	jQuery.fn.wspg_editable = function(url, options) {
	
		return this.each(function() {
			
			var opt = { 
				'type': 'text',
				'url': url,
				'pk': 1,
				'ajaxOptions': {
					'type': 'post'
				},
				'params': options['submitdata'],
				'placeholder': wpsg_ajax.ie_placeholder,
				'emptytext': wpsg_ajax.ie_emptytext,
				'validate': function(value) {
					
				    //if(jQuery.trim(value) == '') { return wpsg_ajax.ie_validate_empty; }
				    
				}				
			};

            if (typeof options.type == "string") opt['type'] = options.type;

            if (options.type == "select" && typeof options.data == "string")
            {
 
                var ar = [];
                var arData = jQuery.parseJSON(options.data);
                var strValue = jQuery(this).html();
                var value = 0;
                
                for (var i in arData)
                {
                    
                    ar.push( { 'value': i, 'text': arData[i] } );
                    if (arData[i] == strValue) value = i;
                    
                }
                                
                // Normale Übergabe eines JSON Strings
                opt.source = ar;
                opt.type = 'select';
                opt.value = value;

            }
            else if (options.type == 'multiarray')
            {

                var ar = [];
                var arData = jQuery.parseJSON(options.data);
 
                for (var i in arData)
                {

                    objData = { 'text': arData[i].name, 'children': [] };

                    for (var j in arData[i]['fields'])
                    {

                        objData['children'].push( { 'value': j, 'text': arData[i]['fields'][j] } );

                    }

                    ar.push(objData);

                }

                opt.source = ar;
                opt.type = 'select';

            }
			else if (options.type == 'string' && typeof options.data == "string")
            {

				var ar = [];
				var arData = jQuery.parseJSON(options.data);

				for (var i in arData)
				{
				
					ar.push( { 
						'value': i,
						'text': arData[i]
					} );
					
					if (arData[i] == jQuery(this).text()) opt.value = i;
					
				}
				
				opt.type = 'select';
				opt.source = ar;
				
			}
			else
			{

				opt.display = function(value, sourceData) {
		        
					jQuery(this).html(sourceData);
				
				};
				
			}

            if (typeof options.callback == "function") opt.success = options.callback;
			
			jQuery(this).editable(opt);
			
		} );
	
	}