Permalink
Browse files

Follow the vocabulary updater pattern and factor out the value-settin…

…g code to a separate method. This aids maintainability and makes the special-casing for kupu more explicit.

svn path=/MoreFieldsAndWidgets/Products.MasterSelectWidget/trunk/; revision=10854
  • Loading branch information...
1 parent a47461f commit 528c0b691fff37822ec21b93fd28a38bc917f712 Martijn Pieters committed Mar 19, 2009
Showing with 8 additions and 11 deletions.
  1. +8 −11 Products/MasterSelectWidget/masterselect.js
View
19 Products/MasterSelectWidget/masterselect.js
@@ -43,28 +43,25 @@
};
// AJAX value handling
+ function updateValue(field, data) {
+ field = $('#archetypes-fieldname-' + field + ' #' + field);
+ field.val(data).change();
+ if (field.is('.kupu-editor-textarea')) // update kupu editor too
+ field.siblings('iframe:first').contents().find('body').html(data);
+ }
function handleMasterValueChange(event) {
var value = $.nodeName(this, 'input') ?
'' + this.checked : $(this).val();
var slave = event.data.slaveid;
var cachekey = [this.id, slave, value].join(':');
- var target = $('#archetypes-fieldname-' + slave + ' #' + slave);
if (cache[cachekey] == undefined)
$.getJSON(event.data.url,
{ field: this.id, slave: slave, value: value },
function(data) {
cache[cachekey] = data;
- target.val(data).change();
- if (target.is('.kupu-editor-textarea'))
- target.siblings('iframe:first').contents().find('body')
- .html(data);
+ updateValue(slave, data);
});
- else {
- target.val(cache[cachekey]).change();
- if (target.is('.kupu-editor-textarea'))
- target.siblings('iframe:first').contents().find('body')
- .html(cache[cachekey]);
- }
+ else updateValue(slave, cache[cachekey]);
};
$.fn.bindMasterSlaveValue = function(slaveid, url) {
var data = { slaveid: slaveid, url: url };

0 comments on commit 528c0b6

Please sign in to comment.