芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/moodledata/localcache/js/ec5f584a03df004fafe2b8f20763e125cc88c3a1
M.form=M.form||{};if(typeof M.form.dependencyManager==='undefined'){var dependencyManager=function(){dependencyManager.superclass.constructor.apply(this,arguments)};Y.extend(dependencyManager,Y.Base,{_locks:null,_hides:null,_dirty:null,_nameCollections:null,_fileinputs:null,initializer:function(){this._locks={};this._hides={};this._dirty={};Y.Object.each(this.get('dependencies'),function(value,i){var elements=this.elementsByName(i);elements.each(function(node){var nodeName=node.get('nodeName').toUpperCase();if(nodeName=='INPUT'){if(node.getAttribute('type').match(/^(button|submit|radio|checkbox)$/)){node.on('click',this.updateEventDependencies,this)}else{node.on('blur',this.updateEventDependencies,this)} node.on('change',this.updateEventDependencies,this)}else if(nodeName=='SELECT'){node.on('change',this.updateEventDependencies,this)}else{node.on('click',this.updateEventDependencies,this);node.on('blur',this.updateEventDependencies,this);node.on('change',this.updateEventDependencies,this)}},this)},this);this.get('form').get('elements').each(function(input){if(input.getAttribute('type')=='reset'){input.on('click',function(){this.get('form').reset();this.updateAllDependencies()},this)}},this);this.updateAllDependencies()},initElementsByName:function(){var names={};var allnames={};Y.Object.each(this.get('dependencies'),function(conditions,i){names[i]=new Y.NodeList();allnames[i]=new Y.NodeList();for(var condition in conditions){for(var value in conditions[condition]){for(var hide in conditions[condition][value]){for(var ei in conditions[condition][value][hide]){names[conditions[condition][value][hide][ei]]=new Y.NodeList();allnames[conditions[condition][value][hide][ei]]=new Y.NodeList()}}}}});this.get('form').get('elements').each(function(node){var name=node.getAttribute('name');if(({}).hasOwnProperty.call(names,name)){names[name].push(node);allnames[name].push(node)}});this.get('form').all('.fitem').each(function(node){var name=node.getData('groupname');if(name&&({}).hasOwnProperty.call(allnames,name)){allnames[name].push(node)}});this._nameCollections={names:names,allnames:allnames}},elementsByName:function(name,includeGroups){if(includeGroups===undefined){includeGroups=!1} var collection=(includeGroups?'allnames':'names');if(!this._nameCollections){this.initElementsByName()} if(!({}).hasOwnProperty.call(this._nameCollections[collection],name)){return new Y.NodeList()} return this._nameCollections[collection][name]},checkDependencies:function(e,dependon){var dependencies=this.get('dependencies'),tohide={},tolock={},condition,value,isHide,lock,hide,checkfunction,result,elements;if(!({}).hasOwnProperty.call(dependencies,dependon)){return!0} elements=this.elementsByName(dependon);for(condition in dependencies[dependon]){for(value in dependencies[dependon][condition]){for(isHide in dependencies[dependon][condition][value]){checkfunction='_dependency'+condition[0].toUpperCase()+condition.slice(1);if(Y.Lang.isFunction(this[checkfunction])){result=this[checkfunction].apply(this,[elements,value,(isHide==="1"),e])}else{result=this._dependencyDefault(elements,value,(isHide==="1"),e)} lock=result.lock||!1;hide=result.hide||!1;for(var ei in dependencies[dependon][condition][value][isHide]){var eltolock=dependencies[dependon][condition][value][isHide][ei];if(({}).hasOwnProperty.call(tohide,eltolock)){tohide[eltolock]=tohide[eltolock]||hide}else{tohide[eltolock]=hide} if(({}).hasOwnProperty.call(tolock,eltolock)){tolock[eltolock]=tolock[eltolock]||lock}else{tolock[eltolock]=lock}}}}} for(var el in tolock){var needsupdate=!1;if(!({}).hasOwnProperty.call(this._locks,el)){this._locks[el]={}} if(({}).hasOwnProperty.call(tolock,el)&&tolock[el]){if(!({}).hasOwnProperty.call(this._locks[el],dependon)||this._locks[el][dependon]){this._locks[el][dependon]=!0;needsupdate=!0}}else if(({}).hasOwnProperty.call(this._locks[el],dependon)&&this._locks[el][dependon]){delete this._locks[el][dependon];needsupdate=!0} if(!({}).hasOwnProperty.call(this._hides,el)){this._hides[el]={}} if(({}).hasOwnProperty.call(tohide,el)&&tohide[el]){if(!({}).hasOwnProperty.call(this._hides[el],dependon)||this._hides[el][dependon]){this._hides[el][dependon]=!0;needsupdate=!0}}else if(({}).hasOwnProperty.call(this._hides[el],dependon)&&this._hides[el][dependon]){delete this._hides[el][dependon];needsupdate=!0} if(needsupdate){this._dirty[el]=!0}} return!0},updateAllDependencies:function(){Y.Object.each(this.get('dependencies'),function(value,name){this.checkDependencies(null,name)},this);this.updateForm()},updateEventDependencies:function(e){var el=e.target.getAttribute('name');this.checkDependencies(e,el);this.updateForm()},updateForm:function(){var el;for(el in this._dirty){if(({}).hasOwnProperty.call(this._locks,el)){this._disableElement(el,!Y.Object.isEmpty(this._locks[el]))} if(({}).hasOwnProperty.call(this._hides,el)){this._hideElement(el,!Y.Object.isEmpty(this._hides[el]))}} this._dirty={}},_disableElement:function(name,disabled){var els=this.elementsByName(name),filepicker=this.isFilePicker(name),editors=this.get('form').all('.fitem [data-fieldtype="editor"] textarea[name="'+name+'[text]"]');els.each(function(node){if(disabled){node.setAttribute('disabled','disabled')}else{node.removeAttribute('disabled')} if(filepicker){var fitem=node.ancestor('.fitem');if(fitem){if(disabled){fitem.addClass('disabled')}else{fitem.removeClass('disabled')}}}});editors.each(function(editor){if(disabled){editor.setAttribute('readonly','readonly')}else{editor.removeAttribute('readonly','readonly')} editor.getDOMNode().dispatchEvent(new Event('form:editorUpdated'))})},_hideElement:function(name,hidden){var els=this.elementsByName(name,!0);els.each(function(node){var e=node.ancestor('.fitem',!0);var label=null,id=null;if(e){if(e.hasClass('fitem_fgroup')){e=node} if(hidden){e.setAttribute('hidden','hidden')}else{e.removeAttribute('hidden')} e.setStyles({display:(hidden)?'none':''});id=node.get('id');if(id){label=Y.all('label[for="'+id+'"]');if(label){if(hidden){label.setAttribute('hidden','hidden')}else{label.removeAttribute('hidden')} label.setStyles({display:(hidden)?'none':''})}}}})},isFilePicker:function(el){if(!this._fileinputs){var fileinputs={};var selector='.fitem [data-fieldtype="filepicker"] input,.fitem [data-fieldtype="filemanager"] input';var els=this.get('form').all(selector);els.each(function(node){fileinputs[node.getAttribute('name')]=!0});this._fileinputs=fileinputs} if(({}).hasOwnProperty.call(this._fileinputs,el)){return this._fileinputs[el]||!1} return!1},_dependencyNotchecked:function(elements,value,isHide){var lock=!1;elements.each(function(){if(this.getAttribute('type').toLowerCase()=='hidden'&&!this.siblings('input[type=checkbox][name="'+this.get('name')+'"]').isEmpty()){return} if(this.getAttribute('type').toLowerCase()=='radio'&&this.get('value')!=value){return} lock=lock||!Y.Node.getDOMNode(this).checked});return{lock:lock,hide:isHide?lock:!1}},_dependencyChecked:function(elements,value,isHide){var lock=!1;elements.each(function(){if(this.getAttribute('type').toLowerCase()=='hidden'&&!this.siblings('input[type=checkbox][name="'+this.get('name')+'"]').isEmpty()){return} if(this.getAttribute('type').toLowerCase()=='radio'&&this.get('value')!=value){return} lock=lock||Y.Node.getDOMNode(this).checked});return{lock:lock,hide:isHide?lock:!1}},_dependencyNoitemselected:function(elements,value,isHide){var lock=!1;elements.each(function(){lock=lock||this.get('selectedIndex')==-1});return{lock:lock,hide:isHide?lock:!1}},_dependencyEq:function(elements,value,isHide){var lock=!1;var hiddenVal=!1;var options,v,selected,values;elements.each(function(){if(this.getAttribute('type').toLowerCase()=='radio'&&!Y.Node.getDOMNode(this).checked){return}else if(this.getAttribute('type').toLowerCase()=='hidden'&&!this.siblings('input[type=checkbox][name="'+this.get('name')+'"]').isEmpty()){hiddenVal=(this.get('value')==value);return}else if(this.getAttribute('type').toLowerCase()=='checkbox'&&!Y.Node.getDOMNode(this).checked){lock=lock||hiddenVal;return} if(this.getAttribute('class').toLowerCase()=='filepickerhidden'){var elementname=this.getAttribute('name');if(elementname&&M.form_filepicker.instances[elementname].fileadded){lock=!1}else{lock=!0}}else if(this.get('nodeName').toUpperCase()==='SELECT'&&this.get('multiple')===!0){values=value.split('|');selected=[];options=this.get('options');options.each(function(){if(this.get('selected')){selected[selected.length]=this.get('value')}});if(selected.length>0&&selected.length===values.length){for(var i in selected){v=selected[i];if(values.indexOf(v)>-1){lock=!0}else{lock=!1;return}}}else{lock=!1}}else{lock=lock||this.get('value')==value}});return{lock:lock,hide:isHide?lock:!1}},_dependencyIn:function(elements,values,isHide){values=values.split('|');var lock=!1;var hiddenVal=!1;var options,v,selected,value;elements.each(function(){if(this.getAttribute('type').toLowerCase()=='radio'&&!Y.Node.getDOMNode(this).checked){return}else if(this.getAttribute('type').toLowerCase()=='hidden'&&!this.siblings('input[type=checkbox][name="'+this.get('name')+'"]').isEmpty()){hiddenVal=(values.indexOf(this.get('value'))>-1);return}else if(this.getAttribute('type').toLowerCase()=='checkbox'&&!Y.Node.getDOMNode(this).checked){lock=lock||hiddenVal;return} if(this.getAttribute('class').toLowerCase()=='filepickerhidden'){var elementname=this.getAttribute('name');if(elementname&&M.form_filepicker.instances[elementname].fileadded){lock=!1}else{lock=!0}}else if(this.get('nodeName').toUpperCase()==='SELECT'&&this.get('multiple')===!0){selected=[];options=this.get('options');options.each(function(){if(this.get('selected')){selected[selected.length]=this.get('value')}});if(selected.length>0&&selected.length===values.length){for(var i in selected){v=selected[i];if(values.indexOf(v)>-1){lock=!0}else{lock=!1;return}}}else{lock=!1}}else{value=this.get('value');lock=lock||(values.indexOf(value)>-1)}});return{lock:lock,hide:isHide?lock:!1}},_dependencyHide:function(elements,value){return{lock:!1,hide:!0}},_dependencyDefault:function(elements,value,isHide){var lock=!1,hiddenVal=!1,values;elements.each(function(){var selected;if(this.getAttribute('type').toLowerCase()=='radio'&&!Y.Node.getDOMNode(this).checked){return}else if(this.getAttribute('type').toLowerCase()=='hidden'&&!this.siblings('input[type=checkbox][name="'+this.get('name')+'"]').isEmpty()){hiddenVal=(this.get('value')!=value);return}else if(this.getAttribute('type').toLowerCase()=='checkbox'&&!Y.Node.getDOMNode(this).checked){lock=lock||hiddenVal;return} if(this.getAttribute('class').toLowerCase()=='filepickerhidden'){var elementname=this.getAttribute('name');if(elementname&&M.form_filepicker.instances[elementname].fileadded){lock=!0}else{lock=!1}}else if(this.get('nodeName').toUpperCase()==='SELECT'&&this.get('multiple')===!0){values=value.split('|');selected=[];this.get('options').each(function(){if(this.get('selected')){selected[selected.length]=this.get('value')}});if(selected.length>0&&selected.length===values.length){for(var i in selected){if(values.indexOf(selected[i])>-1){lock=!1}else{lock=!0;return}}}else{lock=!0}}else{lock=lock||this.get('value')!=value}});return{lock:lock,hide:isHide?lock:!1}}},{NAME:'mform-dependency-manager',ATTRS:{form:{setter:function(value){return Y.one('#'+value)},value:null},dependencies:{value:{}}}});M.form.dependencyManager=dependencyManager} M.form.dependencyManagers={};M.form.initFormDependencies=function(Y,formid,dependencies){if(!Y.Lang.isArray(dependencies)&&!Y.Lang.isObject(dependencies)){return!1} Y.Node.ATTRS.elements={getter:function(){return Y.all(new Y.Array(this._node.elements,0,!0))}};M.form.dependencyManagers[formid]=new M.form.dependencyManager({form:formid,dependencies:dependencies});return M.form.dependencyManagers[formid]};M.form.updateFormState=function(formid){if(formid in M.form.dependencyManagers){M.form.dependencyManagers[formid].updateAllDependencies()}}