Hello,
I am new to Object oriented. But i am triying to improve myself.
My problem;
I have many forms on a page. When a user click on a new or upate link, releated forms shows up in a dialog box and i validate it .
What my problem is i after i validate the forms i want them to go to it’s own callback. Every callback functions is different according to forms.
How can i set different callbacks to each process.
Code below isn’t work exactly. It always alert “test1”;
Thank you.
// JavaScript Document
var process = function() {
this.url ="";
this.panel="";
this.panel_title='';
this.panel_button='';
this.callBack();
this.init();
}
process.prototype = {
init : function() {
//some stuff
},
PanelRender : function()
{
var that = this;
$(this.panel).dialog({
autoOpen: false,
modal: true,
close: function(event,ui)
{
$(this.panel).remove();
}
});
},
PanelOpener : function(html_id)
{
this.url = $(html_id).attr('href');
var that = this;
$(html_id).click(function(e)
{
e.preventDefault();
$(that.panel).dialog("option", "title", that.panel_title);
$(that.panel).dialog("option", "buttons",
[
{text: that.panel_button, click:function(){ $(that.panel + " form").submit() }},
{text:'Cancel', click:function(e){ $(that.panel).dialog('close'); } }
]);
that.ValidateForm();
$(that.panel).dialog('open');
});
},
ValidateForm : function()
{
var that = this;
var form = $(this.panel + ' form');
$(form).validate({
submitHandler: function(){
that.callBack();
}
});
},
callBack : function()
{
//callback function works here
}
}
$(document).ready(function() {
NewProccess = new process();
NewProccess.callBack = function(){ alert("test1") };
NewProccess.panel_button = 'New';
NewProccess.panel = '#new_panel';
NewProccess.panel_title = 'Add form';
NewProccess.PanelRender();
NewProccess.PanelOpener('.new_feature');
EditProccess = new process();
EditProccess.callBack = function(){alert("test2")};
EditProccess.panel_button = 'Update';
EditProccess.panel = '#update_panel';
EditProccess.panel_title = 'Update form';
EditProccess.PanelRender();
EditProccess.PanelOpener('.edit_feature');
});