search-options.nut 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2013 by Domingo Alvarez Duarte <[email protected]>
  3. *
  4. * Licensed under GPLv3, see http://www.gnu.org/licenses/gpl.html.
  5. */
  6. class OurBizSearchOptions
  7. {
  8. search_str = null;
  9. select_fields = null;
  10. group_id = null;
  11. product_id = null;
  12. entity_id = null;
  13. order_id = null;
  14. payment_type_id = null;
  15. query_limit = null;
  16. image_id = null;
  17. account_id = null;
  18. active = null;
  19. cdate = null;
  20. contact = null;
  21. id = null;
  22. inactive = null;
  23. mdate = null;
  24. date = null;
  25. name = null;
  26. description = null;
  27. notes = null;
  28. phone = null;
  29. products = null;
  30. entities = null;
  31. buys = null;
  32. sales = null;
  33. only_prices_older = null;
  34. order_by_creation = null;
  35. order_by_modification = null;
  36. reference = null;
  37. total = null;
  38. group_set = null;
  39. with_images = null;
  40. with_headers = null;
  41. with_accounts = null;
  42. code = null;
  43. headers = null;
  44. accounts = null;
  45. constructor()
  46. {
  47. reset();
  48. }
  49. function reset()
  50. {
  51. search_str = "";
  52. select_fields = "";
  53. active =
  54. cdate =
  55. buys =
  56. contact =
  57. id =
  58. inactive =
  59. mdate = date = total = group_set = false;
  60. name = notes = phone =
  61. products = entities = description = sales = false;
  62. only_prices_older = order_by_creation = order_by_modification =
  63. reference = with_images = false;
  64. with_headers = with_accounts = code = false;
  65. group_id = 0;
  66. product_id = entity_id = order_id = payment_type_id = image_id = account_id = 0;
  67. query_limit = 50;
  68. }
  69. function getPostOptions()
  70. {
  71. local ar = ["search_str="];
  72. if(search_str.size()){
  73. ar.push(url_encode(search_str));
  74. }
  75. if(select_fields.size()){
  76. ar.push("&select_fields=");
  77. ar.push(url_encode(select_fields));
  78. }
  79. foreach(k,v in OurBizSearchOptions){
  80. local val = this[k];
  81. local ktype = type(val);
  82. if(ktype == "integer") {
  83. if(val) ar.push(format("&%s=%d", k, val));
  84. }
  85. else if(ktype == "bool"){
  86. if(val) ar.push(format("&%s=1", k));
  87. }
  88. }
  89. return ar.concat();
  90. }
  91. function getOptionsFromMap(map)
  92. {
  93. search_str = table_rawget(map, "search_str", "");
  94. select_fields = table_rawget(map, "select_fields", "");
  95. search_on = table_rawget(map, "search_on", "1");
  96. foreach(k,v in this){
  97. local ktype = type(v);
  98. if(ktype == "integer") {
  99. local value = table_get(map, k, null);
  100. if(value != null) this[k] = value.tointeger();
  101. }
  102. else if(ktype == "bool"){
  103. this[k] = table_get(map, k, null) != null;
  104. }
  105. }
  106. }
  107. };