duild dev 1.4.6

This commit is contained in:
vitalets 2013-06-27 12:48:18 +04:00
parent 8180096e7e
commit bdd314bd67
6 changed files with 111 additions and 72 deletions

@ -3518,6 +3518,20 @@ $(function(){
//detect whether it is multi-valued //detect whether it is multi-valued
this.isMultiple = this.options.select2.tags || this.options.select2.multiple; this.isMultiple = this.options.select2.tags || this.options.select2.multiple;
this.isRemote = ('ajax' in this.options.select2); this.isRemote = ('ajax' in this.options.select2);
//store function returning ID of item
//should be here as used inautotext for local source
this.idFunc = this.options.select2.id;
if (typeof(this.idFunc) !== "function") {
var idKey = this.idFunc || 'id';
this.idFunc = function (e) { return e[idKey]; };
}
//store function that renders text in select2
this.formatSelection = this.options.select2.formatSelection;
if (typeof(this.formatSelection) !== "function") {
this.formatSelection = function (e) { return e.text; };
}
}; };
$.fn.editableutils.inherit(Constructor, $.fn.editabletypes.abstractinput); $.fn.editableutils.inherit(Constructor, $.fn.editabletypes.abstractinput);
@ -3543,10 +3557,6 @@ $(function(){
$(this).closest('form').parent().triggerHandler('resize'); $(this).closest('form').parent().triggerHandler('resize');
}); });
} }
//store function that extracs ID from element
this.idFunc = this.$input.data('select2').opts.id;
this.formatSelection = this.$input.data('select2').opts.formatSelection;
}, },
value2html: function(value, element) { value2html: function(value, element) {
@ -3582,25 +3592,28 @@ $(function(){
}, },
value2input: function(value) { value2input: function(value) {
//for remote source .val() is not working, need to look in sourceData //for local source use data directly from source (to allow autotext)
if(this.isRemote) { /*
//todo: check value for array if(!this.isRemote && !this.isMultiple) {
var item, items; var items = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc);
//if sourceData loaded, use it to get text for display if(items.length) {
if(this.sourceData) { this.$input.select2('data', items[0]);
items = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc); return;
if(items.length) { }
item = items[0]; }
} */
}
//if item not found by sourceData, use element text (e.g. for the first show) //for remote source just set value, text is updated by initSelection
if(!item) { this.$input.val(value).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit)
item = {id: value, text: $(this.options.scope).text()};
} //if remote source AND no user's initSelection provided --> try to use element's text
//select2('data', ...) allows to set both id and text --> usefull for initial show when items are not loaded if(this.isRemote && !this.isMultiple && !this.options.select2.initSelection) {
this.$input.select2('data', item).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit) var customId = this.options.select2.id,
} else { customText = this.options.select2.formatSelection;
this.$input.val(value).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit) if(!customId && !customText) {
var data = {id: value, text: $(this.options.scope).text()};
this.$input.select2('data', data);
}
} }
}, },

File diff suppressed because one or more lines are too long

@ -3518,6 +3518,20 @@ $(function(){
//detect whether it is multi-valued //detect whether it is multi-valued
this.isMultiple = this.options.select2.tags || this.options.select2.multiple; this.isMultiple = this.options.select2.tags || this.options.select2.multiple;
this.isRemote = ('ajax' in this.options.select2); this.isRemote = ('ajax' in this.options.select2);
//store function returning ID of item
//should be here as used inautotext for local source
this.idFunc = this.options.select2.id;
if (typeof(this.idFunc) !== "function") {
var idKey = this.idFunc || 'id';
this.idFunc = function (e) { return e[idKey]; };
}
//store function that renders text in select2
this.formatSelection = this.options.select2.formatSelection;
if (typeof(this.formatSelection) !== "function") {
this.formatSelection = function (e) { return e.text; };
}
}; };
$.fn.editableutils.inherit(Constructor, $.fn.editabletypes.abstractinput); $.fn.editableutils.inherit(Constructor, $.fn.editabletypes.abstractinput);
@ -3543,10 +3557,6 @@ $(function(){
$(this).closest('form').parent().triggerHandler('resize'); $(this).closest('form').parent().triggerHandler('resize');
}); });
} }
//store function that extracs ID from element
this.idFunc = this.$input.data('select2').opts.id;
this.formatSelection = this.$input.data('select2').opts.formatSelection;
}, },
value2html: function(value, element) { value2html: function(value, element) {
@ -3582,25 +3592,28 @@ $(function(){
}, },
value2input: function(value) { value2input: function(value) {
//for remote source .val() is not working, need to look in sourceData //for local source use data directly from source (to allow autotext)
if(this.isRemote) { /*
//todo: check value for array if(!this.isRemote && !this.isMultiple) {
var item, items; var items = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc);
//if sourceData loaded, use it to get text for display if(items.length) {
if(this.sourceData) { this.$input.select2('data', items[0]);
items = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc); return;
if(items.length) { }
item = items[0]; }
} */
}
//if item not found by sourceData, use element text (e.g. for the first show) //for remote source just set value, text is updated by initSelection
if(!item) { this.$input.val(value).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit)
item = {id: value, text: $(this.options.scope).text()};
} //if remote source AND no user's initSelection provided --> try to use element's text
//select2('data', ...) allows to set both id and text --> usefull for initial show when items are not loaded if(this.isRemote && !this.isMultiple && !this.options.select2.initSelection) {
this.$input.select2('data', item).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit) var customId = this.options.select2.id,
} else { customText = this.options.select2.formatSelection;
this.$input.val(value).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit) if(!customId && !customText) {
var data = {id: value, text: $(this.options.scope).text()};
this.$input.select2('data', data);
}
} }
}, },

File diff suppressed because one or more lines are too long

@ -3518,6 +3518,20 @@ $(function(){
//detect whether it is multi-valued //detect whether it is multi-valued
this.isMultiple = this.options.select2.tags || this.options.select2.multiple; this.isMultiple = this.options.select2.tags || this.options.select2.multiple;
this.isRemote = ('ajax' in this.options.select2); this.isRemote = ('ajax' in this.options.select2);
//store function returning ID of item
//should be here as used inautotext for local source
this.idFunc = this.options.select2.id;
if (typeof(this.idFunc) !== "function") {
var idKey = this.idFunc || 'id';
this.idFunc = function (e) { return e[idKey]; };
}
//store function that renders text in select2
this.formatSelection = this.options.select2.formatSelection;
if (typeof(this.formatSelection) !== "function") {
this.formatSelection = function (e) { return e.text; };
}
}; };
$.fn.editableutils.inherit(Constructor, $.fn.editabletypes.abstractinput); $.fn.editableutils.inherit(Constructor, $.fn.editabletypes.abstractinput);
@ -3543,10 +3557,6 @@ $(function(){
$(this).closest('form').parent().triggerHandler('resize'); $(this).closest('form').parent().triggerHandler('resize');
}); });
} }
//store function that extracs ID from element
this.idFunc = this.$input.data('select2').opts.id;
this.formatSelection = this.$input.data('select2').opts.formatSelection;
}, },
value2html: function(value, element) { value2html: function(value, element) {
@ -3582,25 +3592,28 @@ $(function(){
}, },
value2input: function(value) { value2input: function(value) {
//for remote source .val() is not working, need to look in sourceData //for local source use data directly from source (to allow autotext)
if(this.isRemote) { /*
//todo: check value for array if(!this.isRemote && !this.isMultiple) {
var item, items; var items = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc);
//if sourceData loaded, use it to get text for display if(items.length) {
if(this.sourceData) { this.$input.select2('data', items[0]);
items = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc); return;
if(items.length) { }
item = items[0]; }
} */
}
//if item not found by sourceData, use element text (e.g. for the first show) //for remote source just set value, text is updated by initSelection
if(!item) { this.$input.val(value).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit)
item = {id: value, text: $(this.options.scope).text()};
} //if remote source AND no user's initSelection provided --> try to use element's text
//select2('data', ...) allows to set both id and text --> usefull for initial show when items are not loaded if(this.isRemote && !this.isMultiple && !this.options.select2.initSelection) {
this.$input.select2('data', item).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit) var customId = this.options.select2.id,
} else { customText = this.options.select2.formatSelection;
this.$input.val(value).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit) if(!customId && !customText) {
var data = {id: value, text: $(this.options.scope).text()};
this.$input.select2('data', data);
}
} }
}, },

File diff suppressed because one or more lines are too long