RelatedDataEditor = Class.create(); RelatedDataEditor.applyTo('#Form_EditForm div.RelatedDataEditor'); RelatedDataEditor.prototype = { initialize: function(){ var loading = $(this.id+"_loading"); if(loading){ loading.style.position = "absolute"; } var loaded = $(this.id+"_loaded"); if(loaded){ loaded.style.position = "absolute"; } var ownerForm = this.ownerForm() ownerForm.observeMethod('BeforeSave', this.beforeSave.bind(this)); this.zeroToggle(); }, beforeSave: function(){ if(this.newKeyValue) { var input = document.createElement('input'); input.name=this.id+"[newID]"; input.value=this.newKeyValue; input.style.display = 'none'; this.appendChild(input); } }, reload: function(parentID){ var relatedClass = this.id var url = getAjaxURL('updateRelatedKey', this.getOwnerID(), 'ajax=1&RelatedClass='+relatedClass+'&ParentID='+parentID); var __relatedDataEditor = this; new Ajax.Updater( {success: $(this.id+'_keyholder')}, url, { method: 'get', onFailure: function(response) {errorMessage("Error getting data", response);}, onComplete: function() { Behaviour.apply(__relatedDataEditor); var keyfield = __relatedDataEditor.findKeyField(); keyfield.onchange(); } } ); }, updatingEffect: function(){ var childrenHolder = this.findChildrenHolder(); var loading = $(this.id+"_loading"); if(loading){ loading.style.display = "block"; if(childrenHolder&&!childrenHolder.needToToggleAsBlock){ new Effect.Fade(childrenHolder, {to: .3, duration: 1}); } } }, loadedEffect: function(){ var childrenHolder = this.findChildrenHolder(); var loading = $(this.id+"_loading"); if(loading) loading.style.display = "none"; var loaded = $(this.id+"_loaded"); if(loaded){ loaded.style.display = "block"; new Effect.Fade(loaded); } if(childrenHolder&&!childrenHolder.needToToggleAsBlock) new Effect.Appear(childrenHolder); }, findChildrenHolder: function(){ return $(this.id+'_childrenholder'); }, findKeyField: function(){ return this.getElementsByTagName('select')[0]; }, findChildren: function(entireForm){ if(entireForm){ var f = this.ownerForm(); var allInputs = f.getElementsByTagName('input'); var allTextareas = f.getElementsByTagName('textarea'); }else{ var allInputs = this.getElementsByTagName('input'); var allTextareas = this.getElementsByTagName('textarea'); } var relatedFields = new Array(); var regEx = new RegExp('^'+this.id+'\\\[.+\\\]$'); for(var i=0; i