Here is my code...can you tell me how to make this happen? where does the code belong?
/*Defines the id of my widget*/
function get_my_id_variable_b(){
return "order_id";
}
/*Defines all the variables of my widget without the list variables*/
function get_my_data_variables_b(){
var my_variables = ["order_id","customer", "date", "date_string", "order_type_label", "time_label", "comments", "address", "city", "state", "zip", "contact", "phone", "fax", "email", "instructions", "client_id"];
return my_variables;
}
/*Defines all of the list variables of my widget*/
function get_my_list_id_variables_b(){
var my_variables = ["id_order_type", "id_time"];
return my_variables;
}
/*Returns a json of both variables and id of my widget (without the list variables) */
function get_data_from_interface_b(){
var my_order = {};
var my_variables = get_my_data_variables_b();
for(var i = 0 ; i<my_variables.length; i++){
my_order[my_variables[i]] = RMPApplication.get(my_variables[i]);
}
var id = get_my_id_variable_b();
my_order[id] = uniqueid_b();
return my_order;
}
/*Same as above but does NOT reset client_id as uniqueid*/
function get_data_from_interface_to_update_b(){
var my_order = {};
var my_variables = get_my_data_variables_b();
for(var i = 0 ; i<my_variables.length; i++){
my_order[my_variables[i]] = RMPApplication.get(my_variables[i]);
}
return my_order;
}
/*Sets both of all variables and id of my widget (without the list variables) */
function set_data_to_interface_b(data){
var my_order = data[0];
var my_variables = get_my_data_variables_b();
//Set The Data Of All Fields
for(var i = 0 ; i<my_variables.length; i++){
RMPApplication.set(my_variables[i],my_order[my_variables[i]]);
}
//Set The Data For ID Field
var id = get_my_id_variable_b();
RMPApplication.set(id,my_order[id]);
}
function empty_data_of_interface_b(){
//empty all fields
var my_variables = get_my_data_variables_b();
for(var i = 0 ; i<my_variables.length; i++){
RMPApplication.set(my_variables[i],"");
}
//Empty ID Field
var id = get_my_id_variable_b();
RMPApplication.set(id,"");
//reset all the lists
var my_list_variables = get_my_list_id_variables_b();
for(var i = 0 ; i<my_list_variables.length; i++){
eval(my_list_variables[i]).reset();
}
}
function add_order() {
var my_order = get_data_from_interface_b();
col_deli_orders.saveCallback(my_order, add_order_ok, add_order_ko);
}
//add item ok
function add_order_ok(result) {
id_report_b.refresh();
}
function add_order_ko(result) {
//Error while adding planning in the collection
id_html_msg.setHtml("<font color='red'><i>Error while adding new customer</font><i>");
}
//load_item
function load_order(order_id) {
empty_data_of_interface_b();
var my_pattern = {};
var id = get_my_id_variable_b();
my_pattern[id]= order_id;
col_deli_orders.listCallback(my_pattern, {}, load_order_ok, load_order_ko);
}
//load_planning
function load_order_ok(result) {
set_data_to_interface_b(result);
id_split_widget.setVisible(true);
id_split_one.setVisible(true);
id_split_three.setVisible(true);
id_split_four.setVisible(false);
id_split_six.setVisible(false);
id_six_report.setVisible(false);
id_menu_items.setVisible(false);
id_split_seven.setVisible(false);
id_back_button_a.setVisible(false);
id_back_button_b.setVisible(false);
}
function load_order_ko(result) {
id_html_msg.setHtml("<font color='red'><i>Error while loading item</font><i>");
id_report_b.refresh();
}
function update_item() {
var my_order = get_data_from_interface_to_update_b();
var my_pattern = {};
var id = get_my_id_variable_b();
my_pattern[id] = RMPApplication.get(id);
col_deli_orders.updateCallback(my_pattern, my_order, update_order_ok, update_order_ko);
}
//udpate item
function update_order_ok(result) {
id_report_b.refresh();
id_html_msg.setHtml("<font color='green'><i>Changes saved</font><i>");
}
function update_order_ko(result) {
//Error while employee planning in the collection
id_html_msg.setHtml("<font color='red'><i>Error while saving item</font><i>");
}
function revise_order() {
var my_order = get_data_from_interface_to_update_b();
var my_pattern = {};
var id = get_my_id_variable_b();
my_pattern[id] = RMPApplication.get(id);
col_deli_orders.updateCallback(my_pattern, my_order, revise_order_ok, revise_order_ko);
}
//revise customer
function revise_order_ok(result) {
id_report_b.refresh();
edit_button.setVisible(true);
edit_button.setActive(true);
save_button.setVisible(false);
save_button.setActive(true);
cancel_button.setVisible(true);
cancel_button.setActive(false);
open_report_button.setVisible(true);
open_report_button.setActive(true);
make_order_inactive();
id_html_msg.setHtml("<font color='green'><i>Changes saved</font><i>");
}
function revise_order_ko(result) {
//Error while employee planning in the collection
id_html_msg.setHtml("<font color='red'><i>Error while saving item</font><i>");
}
function delete_order(order_id) {
check = confirm("Do you really want to delete this order?");
if (check) {
var my_pattern = {};
var id = get_my_id_variable_b();
my_pattern[id] = order_id;
col_deli_orders.removeCallback(my_pattern, delete_order_ok, delete_order_ko);
}}
//delete_customer
function delete_order_ok(result) {
id_report_b.refresh();
//Empty the data
empty_data_of_interface_b();
}
function delete_order_ko(result) {
//Error while deleting item from the collection
id_html_msg.setHtml("<font color='red'><i>Error while deleting item</font><i>");
}
function uniqueid_b(){
var idstr=String.fromCharCode(Math.floor((Math.random()*25)+65));
do {
// between numbers and characters (48 is 0 and 90 is Z (42-48 = 90)
var ascicode=Math.floor((Math.random()*42)+48);
if (ascicode<58 || ascicode>64){
// exclude all chars between : (58) and @ (64)
idstr+=String.fromCharCode(ascicode);
}
} while (idstr.length<32);
return (idstr);
}