|
var HiddenSubform = { |
|
update: function(object) { |
|
switch(object.nodeName) { |
|
case 'SELECT': |
|
this.updateSelect(object); |
|
break; |
|
case 'INPUT': |
|
if(object.getAttribute('type') == 'checkbox') { |
|
this.updateCheckbox(object); |
|
} |
|
break; |
|
} |
|
}, |
|
updateCheckbox: function(checkbox) { |
|
// No ajax call, this should just turn a dom element on or off |
|
var sel = checkbox.getAttribute('show'); |
|
if(sel) { |
|
var dom = document.querySelector(sel); |
|
if(dom) { |
|
if(checkbox.checked) { |
|
removeClass(dom, 'hidden'); |
|
} else { |
|
addClass(dom, 'hidden'); |
|
} |
|
} |
|
} |
|
}, |
|
updateSelect: function(select) { |
|
var selectedIndex = select.options.selectedIndex; |
|
for (var i = 0; i < select.options.length; i++) { |
|
var sel = select.options[i].getAttribute('show'); |
|
if (sel) { |
|
var dom = document.querySelector(sel); |
|
if (dom) { |
|
if (i == selectedIndex) { |
|
removeClass(dom, 'hidden'); |
|
} else { |
|
addClass(dom, 'hidden'); |
|
} |
|
} |
|
} |
|
} |
|
var url = select.getAttribute('url'); |
|
var form = this.getForm(select); |
|
if(form && url) { |
|
// Serialize using the AjaxForm serializer |
|
var data = AjaxForm.serialize(form); |
|
microAjax(url, this.callback_response.bind(this), data); |
|
} |
|
}, |
|
getForm: function(node) { |
|
/** |
|
* Traverse up the tree until we find the parent form |
|
* @param {dom} !node The node we are wanting to find the parent of |
|
* @return {dom} The form element, or null if none found |
|
*/ |
|
if(!node) { |
|
return null; |
|
} |
|
var par = node.parentNode; |
|
if(par && par.nodeName == 'FORM') { |
|
return par; |
|
} |
|
return this.getForm(par); |
|
}, |
|
callback_response: function(json) { |
|
JsonProcessor.run(json); |
|
} |
|
}; |