summaryrefslogtreecommitdiff
path: root/views/js/editable.js
blob: a21962af629d90b013392624ba16585acc5f8c2e (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

	/**
	 * Wrapper, um die Editierfunktion austauschbarer zu machen
	 */
	jQuery.fn.wpsg_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 (typeof options.type == "format") opt['format'] = options.format;
			if (typeof options.type == "viewformat") opt['viewformat'] = options.viewformat;
			if (typeof options.type == "template") opt['template'] = options.template;

			if (options.type == "select" && Array.isArray(options.data))
			{
			 	 
				var value = "0";
				var strValue = jQuery(this).html();
				
				for (var i in options.data)
				{
				
					if (options.data[i].text == strValue) value = options.data[i].value;
					
				}
				
				opt.source = options.data;
                opt.type = 'select';
                opt.value = value;
				
			}			 
            else if (options.type == 'multiarray')
            {

                var ar = [];
                var arData = jQuery.parseJSON(options.data);
				var strValue = jQuery(this).html();
 
                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] } );

						if (arData[i]['fields'][j] == strValue) value = j;
						
                    }

                    ar.push(objData);

                }

                opt.source = ar;
                opt.type = 'select';
				opt.value = value; //j;

			}
			else if (options.type == 'checklist')
			{
				
				opt.type = 'checklist';
				opt.source = [];
				opt.value = options.value;
				
				for (var i in options.data)
				{
				
					opt.source.push( { value: i, text: options.data[i] } );
					
				}
				
			}
			else
			{

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

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