Răsfoiți Sursa

Small code refactore and fixes.

mingodad 13 ani în urmă
părinte
comite
0b9aa35e89

+ 15 - 5
SquiLu-ourbiz/ourbiz-fltk.nut

@@ -104,6 +104,13 @@ class Fl_Multiline_Input extends Fl_Input {
 	}
 }
 
+class Fl_Multiline_Output extends Fl_Output {
+	constructor(px, py, pw, ph, pl=null){
+		base.constructor(px, py, pw, ph, pl);
+		type(4);
+	}
+}
+
 class Fl_Box_ClearLabel extends Fl_Box {
 	constructor(px, py, pw, ph, pl=null){
 		base.constructor(px, py, pw, ph, pl);
@@ -1048,7 +1055,10 @@ class MyListSearchWindow extends ListSearch {
 	_sab = null;
 	_callee_cb = null;
 
-	constructor(){
+	//the parameter is here only to remember derived classes that it can be called
+	//without to create a new instance that do not start with default search results
+	//mainly when it is called asyncronously (in that case a undesirable mix of both data will happen)
+	constructor(doInitialSearch){
 		base.constructor();
 		_search_options = OurBizSearchOptions();
 		grid->callback_when(FLVEcb_ROW_CHANGED | FLVEcb_CLICKED | FLVEcb_ROW_HEADER_CLICKED);
@@ -1369,7 +1379,7 @@ class EntitiesListSearch extends MyListSearchWindow {
 	_sales_orders_list = null;
 
 	constructor(doInitialSearch=true) {
-		base.constructor();
+		base.constructor(doInitialSearch);
 		label(_tr("Entities List Search"));
 		local cols_info = [
 			"id|ID|6|R",
@@ -1435,7 +1445,7 @@ class EntitiesListSearch extends MyListSearchWindow {
 			}
 			break;
 			case 1:{
-				local products_list = ProductsListSearch();
+				local products_list = ProductsListSearch(false);
 				//products_list.callback(delete_on_window_close_cb);
 				local so = OurBizSearchOptions();
 				so.entity_id = grid->get_row_id(row);
@@ -1640,7 +1650,7 @@ class ProductsListSearch extends MyListSearchWindow {
 
 	constructor(doInitialSearch=true) {
 		_last_image_id = 0;
-		base.constructor();
+		base.constructor(doInitialSearch);
 		_search_options = OurBizSearchOptions();
 		label(_tr("Products List Search"));
 		local cols_info = [
@@ -2001,7 +2011,7 @@ class OrdersListSearch extends MyListSearchWindow {
 	_search_wp = null;
 
 	constructor(doInitialSearch=true) {
-		base.constructor();
+		base.constructor(doInitialSearch);
 		label(_tr("Orders List Search"));
 		local cols_info = [
 			"id|ID|6|R",

+ 7 - 29
SquiLu-ourbiz/ourbiz.nut

@@ -1197,8 +1197,7 @@ select p.id,
 			mf.write([==[
 and p.id in(
 select product_id from orders_lines where order_id in (
-	select id from orders where entity_id = " , so.entity_id
-	order by id desc)) ]==]);
+	select id from orders where entity_id = ]==] , so.entity_id, " order by id desc)) ");
 		}
 		else if (search_str && search_str.len() > 0){
 			if (so.id && so.id != 0) mf.write(" and p.id = " , so.search_str.tointeger());
@@ -1228,7 +1227,7 @@ select product_id from orders_lines where order_id in (
 		else mf.write(" order by 3 ");
 
 		if (so.query_limit && so.query_limit != 0) mf.write(" limit " , so.query_limit);
-		//debug_print(tostring(mf), "\n")
+		//debug_print("\n", mf.tostring(), "\n")
 		return  mf.tostring();
 	}
 
@@ -1505,18 +1504,6 @@ function group_dump_data(db, out_result, tbl){
 	out_result.write("]");
 }
 
-function send_http_error_500(request, err_msg){
-	if(AT_DEV_DBG) {
-		foreach(k,v in get_last_stackinfo()) debug_print("\n", k, ":", v);
-		debug_print("\n", err_msg, "\n")
-	}
-	gmFile.clear();
-	gmFile.write("HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: ", err_msg.len(), "\r\n\r\n", err_msg);
-	//debug_print(tostring(gmFile), "\n")
-	request.write_blob(gmFile);
-	return true;
-}
-
 function ourbizDbMobile(request){
 	local data = {};
 	data.page_name = "list_products";
@@ -1582,15 +1569,10 @@ Content-Length: %d
 		}
 
 		if (sql){
-			//try {
-				local stmt = db.prepare(sql);
-				//debug_print(sql, "\n", db.errmsg(), "\n")
-				data = stmt.asSleArray();
-				stmt.finalize();
-			//}
-			//catch(e){
-			//	return send_http_error_500(request, e);
-			//}
+			local stmt = db.prepare(sql);
+			//debug_print(sql, "\n", db.errmsg(), "\n")
+			data = stmt.asSleArray();
+			stmt.finalize();
 		}
 		else if (gmFile.len() > 0){
 			data = gmFile.tostring();
@@ -1742,11 +1724,7 @@ function ourbizDbAction(request){
 		gmFile.clear();
 		local db_manager = db_ourbiz_tables.get(tbl, null);
 		if (db_manager){
-			//try {
-				result = db_manager.db_action(db, data);
-			//} catch(e){
-			//	return send_http_error_500(request, e);
-			//}
+			result = db_manager.db_action(db, data);
 		}
 		if (result != null){
 			gmFile.clear();

+ 11 - 0
SquiLu-ourbiz/sq-server-plugin.nut

@@ -827,6 +827,17 @@ if(AT_DEV_DBG || !globals.get("ourbizDB", false)) {
 	dofile(APP_CODE_FOLDER + "/ourbiz.nut");
 }
 
+function send_http_error_500(request, err_msg){
+	if(AT_DEV_DBG) {
+		foreach(k,v in get_last_stackinfo()) debug_print("\n", k, ":", v);
+		debug_print("\n", err_msg, "\n")
+	}
+	local response = format("HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: %d\r\n\r\n%s", 
+		err_msg.len(),  err_msg);
+	request.write(response, response.len());
+	return true;
+}
+
 local uri_handlers = {
 	["/SQ/testParams"] = function(request){
 		request.print("HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n")

+ 1 - 8
SquiLu-ourbiz/sq-server.nut

@@ -67,14 +67,7 @@ local mongoose_start_params = {
 				return handle_request(request);
 			}
 			catch(exep){
-				if(AT_DEV_DBG) {
-					foreach(k,v in get_last_stackinfo()) debug_print("\n", k, ":", v);
-					debug_print("\n", exep, "\n")
-				}
-				local response = format("HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: %d\r\n\r\n%s", 
-					exep.len(),  exep);
-				request.write(response, response.len());
-				return true;
+				return send_http_error_500(request, exep);
 			}
 		}
 		else if(event == "MG_EVENT_LOG"){