Skip to content

Instantly share code, notes, and snippets.

@lsmith
Forked from anonymous/gist:432567
Created June 10, 2010 05:02
Show Gist options
  • Save lsmith/432575 to your computer and use it in GitHub Desktop.
Save lsmith/432575 to your computer and use it in GitHub Desktop.
/**
* Dispatches clicks to the appropriate handler(s)
*
* (etc)
*/
dispatchClick: function (e) {
var classes = this.get('className').split(/\w+/),
i;
for (i = classes.length - 1; i >= 0; --i) {
if (clickHandler[classes[i]]) {
clickHandler[classes[i]].apply(this, arguments);
}
}
},
clickHandler: {
// whatever this.CSS_NAMES.BIZ_SUBMIT is
'biz-submit': this.handleBIZClick,
...
},
/**
* Pre-defined method. Gets called when module finishes loading to page
* @param {String} viewName The type of view
* @method onviewload
* @return {Void}
*/
onviewload: function(viewName){
this.viewNode = this.api.getViewNode(viewName);
this.viewNode.delegate('click', this.dispatchClick,
'.' + [
this.CSS_NAMES.BIZ_SUBMIT,
this.CSS_NAMES.BIZ_PHOTOUP_START,
this.CSS_NAMES.BIZ_PHOTOUP_STOP,
this.CSS_NAMES.BIZ_PHOTOUP_SUBMIT].join(',.'), this);
if (this.Y.one('#mod_detail-card_editcontainer')){
// No need to pass 'this' as parameter
this.Y.later(5000, this, this.autosave, null, true);
};
return true;
},
/**
* Autosave
* @method autosave
* @return {boolean}
*/
autosave : function(){
var frm=document.forms.formDetailCardSubmit;
var changed=false;
if(frm.auto_title.value!=frm.biztitle.value){
changed=true;
}
if(changed===false&&frm.auto_phone.value!=frm.bizphone.value){
changed=true;
}
if(changed===false&&frm.auto_line1.value!=frm.bizaddr_line1.value){
changed=true;
}
if(changed===false&&frm.auto_city.value!=frm.bizaddr_city.value){
changed=true;
}
if(changed===false&&frm.auto_county.value!=frm.bizaddr_county.value){
changed=true;
}
if(changed===false&&frm.auto_state.value!=frm.bizaddr_state.value){
changed=true;
}
if(changed===false&&frm.auto_zip.value!=frm.bizzip.value){
changed=true;
}
if(changed===false&&frm.auto_email.value!=frm.bizemail.value){
changed=true;
}
//if(changed===false&&frm.auto_photos.value!=frm.bizphone.value){
// changed=true;
//}
if(changed){
this.loadContent(true);
}
}
/**
* Changes the currently opened tab. This involves making a request to
* the server.
* @param {boolean} autosave yes or no
* @method loadContent
* @return {Void}
*/
loadContent: function(autosaveYN) {
var url = "/upload/sherpa/glfe_CardInsert.php";
if(autosaveYN){
url+="?autosave=yes"
}
this.Y.io(url, {
method: 'POST',
form: {
id: 'formDetailCardSubmit',
useDisabled : true
},
on: {
start: function () {},
success: this.handleContentChange
},
context: this,
arguments: [ { _parent: this, autosave: autosaveYN } ]
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment