Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 528c0b691fff37822ec21b93fd28a38bc917f712 1 parent a47461f
Martijn Pieters authored

Showing 1 changed file with 8 additions and 11 deletions. Show diff stats Hide diff stats

  1. +8 11 Products/MasterSelectWidget/masterselect.js
19 Products/MasterSelectWidget/masterselect.js
@@ -43,28 +43,25 @@
43 43 };
44 44
45 45 // AJAX value handling
  46 + function updateValue(field, data) {
  47 + field = $('#archetypes-fieldname-' + field + ' #' + field);
  48 + field.val(data).change();
  49 + if (field.is('.kupu-editor-textarea')) // update kupu editor too
  50 + field.siblings('iframe:first').contents().find('body').html(data);
  51 + }
46 52 function handleMasterValueChange(event) {
47 53 var value = $.nodeName(this, 'input') ?
48 54 '' + this.checked : $(this).val();
49 55 var slave = event.data.slaveid;
50 56 var cachekey = [this.id, slave, value].join(':');
51   - var target = $('#archetypes-fieldname-' + slave + ' #' + slave);
52 57 if (cache[cachekey] == undefined)
53 58 $.getJSON(event.data.url,
54 59 { field: this.id, slave: slave, value: value },
55 60 function(data) {
56 61 cache[cachekey] = data;
57   - target.val(data).change();
58   - if (target.is('.kupu-editor-textarea'))
59   - target.siblings('iframe:first').contents().find('body')
60   - .html(data);
  62 + updateValue(slave, data);
61 63 });
62   - else {
63   - target.val(cache[cachekey]).change();
64   - if (target.is('.kupu-editor-textarea'))
65   - target.siblings('iframe:first').contents().find('body')
66   - .html(cache[cachekey]);
67   - }
  64 + else updateValue(slave, cache[cachekey]);
68 65 };
69 66 $.fn.bindMasterSlaveValue = function(slaveid, url) {
70 67 var data = { slaveid: slaveid, url: url };

0 comments on commit 528c0b6

Please sign in to comment.
Something went wrong with that request. Please try again.