/** * 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") { // Normale Übergabe eines JSON Strings opt.source = jQuery.parseJSON(options.data); opt.type = 'select'; } 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); } ); }