Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.53 KB | None | 0 0
  1. $("#builder").queryBuilder({
  2. filters: [{
  3. id: "Status",
  4. input: "select",
  5. multiple: true,
  6. operators: ["in"],
  7. default_value: 'SbscStSubscriberOptIn',
  8. values: {
  9. SbscStSubscriberOptIn: "SubscriberOptIn",
  10. SbscStSubscriberDoubleOptIn: "SubscriberDoubleOptIn",
  11. SbscStActivatedOpener: "ActivatedOpener",
  12. SbscStActivatedClicker: "ActivatedClicker"
  13. }
  14. },{
  15. id: "ISP",
  16. input: "select",
  17. multiple: true,
  18. operators: ["in", "not_in"],
  19. default_value: 'Google',
  20. values: {
  21. Google: "Gmail",
  22. Yahoo: "Yahoo",
  23. Hotmail: "Hotmail",
  24. Aol: "Aol"
  25. }
  26. },/*{
  27. id: "Activate raw profile",
  28. input: "text",
  29. type: "string",
  30. operators: ["equal"],
  31. default_value: 0,
  32. validation: {
  33. min: 0
  34. }
  35. }, */{
  36. id: "Last activity date",
  37. input: "text",
  38. operators: ["not_equal",'less', 'greater', 'equal','less_or_equal','greater_or_equal'],
  39. unique: true
  40. }, {
  41. id: "Registration date",
  42. type: "date",
  43. operators: ["not_equal",'less', 'greater', 'equal','less_or_equal','greater_or_equal'],
  44. unique: true
  45. }, {
  46. id: "Were sent current campaign",
  47. input: "text",
  48. type: "string",
  49. operators: ["not_equal"],
  50. validation: {
  51. min: 0
  52. }
  53. }
  54. /*, {
  55. id: "Were not sent current campaign",
  56. input: "text",
  57. type: "string",
  58. operators: ["equal"],
  59. default_value: 0,
  60. validation: {
  61. min: 0
  62. }
  63. }, {
  64. id: "Were sent [message]",
  65. input: "text",
  66. type: "string",
  67. operators: ["not_equal"],
  68. validation: {
  69. min: 0
  70. }
  71. }*/
  72. ]
  73. });
  74.  
  75.  
  76. $(".group-conditions:first").append("<a class='btn big' onclick='$(\"#builder\").queryBuilder(\"reset\");return false;'>Reset</a>");
  77.  
  78. function parseJson(result) {
  79. var operator = {
  80. "is later than": "greater",
  81. "is earlier than": "less",
  82. "is more than x days/months/years passed": "less",
  83. "in": "equal",
  84. "not_in": "notequal",
  85. "is equal": "equal",
  86. "is exactly x days/months/years passed": "equal",
  87. "Were sent [message]" : "less",
  88. "Were sent current campaign" : "less",
  89. "Were not sent current campaign" : "less"
  90. };
  91. var id = {
  92. "Status": "SentRuleConditionByProfileStatus",
  93. "ISP": "SentRuleConditionByISP",
  94. "Activate raw profile": "SendRuleActivateRawProfile",
  95. "Last activity date": "SentRuleConditionByLastActionDate",
  96. "Registration date": "SentRuleConditionByRegDate",
  97. "Were sent [message]": "SentRuleConditionByLastSentDate",
  98. "Were sent current campaign": "SentRuleConditionByLastSentDate",
  99. "Were not sent current campaign": "SentRuleConditionByLastSentDate"
  100. };
  101. var converterType = {
  102. "Days": "SentRuleDateConverterDaysAgo",
  103. "Date": "SentRuleDateConverterDate"
  104. };
  105. var final = {};
  106. final["Condition"] = [];
  107.  
  108. if (!result["rules"])
  109. return final;
  110.  
  111. for (var j = 0; j < result["rules"].length; j++) {
  112. var re = {};
  113. var converterValue = {};
  114. var converter = "";
  115. var condition = {};
  116. var operatorText = "";
  117. for (var i in result["rules"][j]) {
  118.  
  119. if (result["rules"][j]["id"] == "Status") {
  120. re["AllowedStatuses"] = result["rules"][j]["value"];
  121. condition["ConditionType"] = id[result["rules"][j]["id"]];
  122. } else if (result["rules"][j]["id"] == "ISP") {
  123. re["AllowedISPs"] = result["rules"][j]["value"];
  124. condition["ConditionType"] = id[result["rules"][j]["id"]];
  125. if (i == "operator") {
  126. re["Operation"] = operator[result["rules"][j]["operator"]];
  127. }
  128. } else if (result["rules"][j]["id"] == "Activate raw profile") {
  129. condition["ConditionType"] = id[result["rules"][j]["id"]];
  130. } else if (i == "id") {
  131. condition["ConditionType"] = id[result["rules"][j][i]];
  132. } else if (i == "operator") {
  133. var len = parseInt($(".rule-container:last").attr("id").replace(/[^-0-9]/gim, ""));
  134. for (var k = 0; k < $(".rule-filter-container").length + len; k++) {
  135. var filter = $(".rule-filter-container select[name='builder_rule_" + k + "_filter']");
  136. var filterChecked = $(".rule-filter-container select[name='builder_rule_" + k + "_filter'] option:checked").text();
  137. var value = $(".rule-value-container input[name='builder_rule_" + k + "_value_0']");
  138. if (value.val() == result["rules"][j]["value"] && filter.val() == result["rules"][j]["id"]) {
  139. operatorText = filter.parent(".rule-filter-container").parent(".rule-container").find(".rule-operator-container select option:checked").text();
  140. converter = filter.parent(".rule-filter-container").parent(".rule-container").find(".rule-value-container select.rule-date-type").val();
  141. if (result["rules"][j]["id"] == "Were sent [message]" || result["rules"][j]["id"] == "Were sent current campaign" || result["rules"][j]["id"] == "Were not sent current campaign") {
  142. re["Operation"] = operator[filterChecked];
  143. if(result["rules"][j]["id"] != "Were sent [message]"){
  144. re["EmailId"] = parseInt($('input[name="emailId"]').val())
  145. }
  146. } else {
  147. re["Operation"] = operator[operatorText];
  148. }
  149. if (result["rules"][j]["id"] == "Were sent [message]") {
  150. re["EmailId"] = parseInt(filter.parent(".rule-filter-container").parent(".rule-container").find(".rule-email-container input").val())
  151. }
  152. }
  153. }
  154. } else if (i == "value") {
  155. if (converter == "Days") {
  156. converterValue[converter] = parseInt(result["rules"][j][i]);
  157. re["ConverterType"] = converterType[converter];
  158. } else {
  159. if(result["rules"][j]["id"] == "Were not sent current campaign"){
  160. converterValue["Date"] = 1;
  161. }else {
  162. var explode_date = result["rules"][j][i].split('/');
  163. var date_reform = explode_date[1] + '/' + explode_date[0] + '/' + explode_date[2];
  164. var dateObject = new Date(Date.UTC(explode_date[2], explode_date[1] - 1, explode_date[0]));
  165. var timestamp = dateObject.valueOf();
  166. timestamp = String(timestamp);
  167. timestamp = timestamp.substring(0, timestamp.length - 3);
  168. timestamp = parseInt(timestamp);
  169. converterValue["Date"] = timestamp;
  170. }
  171. re["ConverterType"] = converterType["Date"];
  172. }
  173. re["Converter"] = converterValue;
  174. }
  175. }
  176. condition["Condition"] = re;
  177. if (result["condition"] == "AND") {
  178. final["ConditionType"] = "SentRuleConditionAnd";
  179. } else if (result["condition"] == "OR") {
  180. final["ConditionType"] = "SentRuleConditionOr";
  181. }
  182. if (result["rules"][j]["id"]) {
  183. final["Condition"].push(condition);
  184. }
  185. }
  186. return final;
  187. }
  188.  
  189.  
  190. $(".query-builder").on("click", function() {
  191. setTimeout(refreshBuilder,0);
  192. });
  193.  
  194. function refreshBuilder() {
  195. var rules = $(".rules-group-body .rules-list li");
  196. var selectValues = { "Please select" : "none" , "is exactly x days/months/years passed" : 'less_or_equal', "is more than x days/months/years passed" : "greater_or_equal" , "is later than" : 'greater' , "is earlier than" : 'less' , "is equal" : "equal"};
  197. var len = parseInt($(".rule-container:last").attr("id").replace(/[^-0-9]/gim, ''));
  198. var operatorText = "";
  199. var filterText = "";
  200. for (var j = 0; j <= len; j++) {
  201. var value = $(".rule-value-container input[name='builder_rule_" + j + "_value_0']");
  202. var filter = $(".rule-filter-container select[name='builder_rule_" + j + "_filter']");
  203. if (value.val() == undefined) {
  204. var value = $(".rule-value-container select[name='builder_rule_" + j + "_value_0']");
  205. var parent = value.parent(".multiselect").parent(".rule-value-container").parent(".rule-container");
  206. var filterParent = filter.parent(".rule-filter-container");
  207. filterParent.find("span").remove();
  208. filterParent.find("select").css("color", "#fff");
  209. parent.find(".rule-email-container input").remove();
  210. parent.find(".rule-email-container span").remove();
  211. //parent.find(".rule-operator-container").css({
  212. // "width": "0",
  213. // "opacity": "0"
  214. //});
  215. //parent.find(".rule-operator-container select").css("width", "0");
  216. //if (parent.find(".rule-filter-container span").length == 0) {
  217. // parent.find(".rule-filter-container").append("<span> IN </span>");
  218. //}
  219.  
  220. parent.find(".rule-operator-container").css({
  221. "width": "auto",
  222. "opacity": "1"
  223. });
  224. if (value.parent(".multiselect").find(".select2-hidden-accessible").length == 0 && value.parent(".multiselect").length > 0) {
  225. $(".select-2").select2();
  226. }
  227. } else {
  228. var parent = value.parent(".rule-value-container").parent(".rule-container");
  229. var operator = parent.find(".rule-operator-container select option:checked").text();
  230. var operator_val = parent.find(".rule-operator-container select option:checked").val();
  231. var filter_select = parent.find(".rule-filter-container select").val();
  232. parent.find(".rule-filter-container span").remove();
  233. parent.find(".rule-filter-container select").css("color", "#fff");
  234. if (filter_select != "Status" && filter_select != "ISP" && filter_select != "Were not sent current campaign" && filter_select != "Activate raw profile" && (operator_val == "not_equal" || operator_val == 'less' || operator_val == 'greater' || operator_val == 'equal' || operator_val == 'greater_or_equal' || operator_val == 'less_or_equal' || operator_val == undefined)) {
  235. parent.find(".rule-operator-container select").find("option").remove().end()
  236. for (var i in selectValues) {
  237. if(operator_val == selectValues[i]){
  238. parent.find(".rule-operator-container select").append("<option value='" + selectValues[i] + "' selected>" + i + "</option>");
  239. }else {
  240. parent.find(".rule-operator-container select").append("<option value='" + selectValues[i] + "'>" + i + "</option>");
  241. }
  242. }
  243. }
  244. if (operator.length > 0) {
  245. operatorText = parent.find(".rule-operator-container select option:checked").text();
  246. parent.find(".rule-operator-container span").remove();
  247. parent.find(".rule-operator-container").append("<span class='operator-text'>" + operatorText + "</span>");
  248. parent.find(".rule-operator-container select").css({
  249. "z-index": 9,
  250. "position": 'absolute',
  251. "top": 10,
  252. "opacity": 0.6,
  253. "color": '#191919'
  254. });
  255. }
  256. if (operator == "is later than" || operator == "is earlier than" || operator == "is later or equal" || operator == "is earlier or equal" || operator == "is equal") {
  257. parent.find(".rule-date-type").remove();
  258. parent.find(".rule-date-passed").remove();
  259. parent.find(".rule-value-container input").css('display','inherit');
  260. parent.find(".rule-operator-container").css({
  261. "width": "0",
  262. "opacity": "0"
  263. });
  264. parent.find(".rule-operator-container select").css("width", "0");
  265. if (parent.find(".rule-value-container .input-group-addon").length == 0) {
  266. value.attr("id", "datepicker_" + j)
  267. }
  268. $("#datepicker_" + j).datepicker({ dateFormat: 'dd/mm/yy' })
  269. } else if (operator == "is exactly x days/months/years passed" || operator == "is more than x days/months/years passed" || filter_select == "Were sent [message]" || filter_select == "Were sent current campaign") {
  270. if (parent.find(".rule-value-container .hasDatepicker").length > 0) {
  271. $("#datepicker_" + j).datepicker("hide")
  272. }
  273. if (parent.find(".rule-date-type").val() == undefined) {
  274. parent.find(".rule-value-container").append("<select class='form-control inputbox rule-date-type'><option>Days</option><!--<option>Month</option><option>Years</option>--></select><span class='rule-date-passed'> Passed</span>");
  275. }
  276.  
  277. parent.find(".rule-value-container input").css('display','inherit');
  278. operatorText = parent.find(".rule-operator-container select option:checked").text();
  279. operatorText = operatorText.replace(operatorText.substr(operatorText.indexOf(" x ")), "");
  280. parent.find(".rule-operator-container span").remove();
  281. parent.find(".rule-operator-container").append("<span class='operator-text'>" + operatorText + "</span>");
  282. parent.find(".rule-operator-container select").css({
  283. "z-index": 9,
  284. "position": 'absolute',
  285. "top": 10,
  286. "opacity": 0.6,
  287. "color": '#191919'
  288. });
  289. if (value.val() != undefined) {
  290. if (value.val().indexOf("2015") >= 0)
  291. value.val("")
  292. }
  293. } else {
  294. parent.find(".rule-value-container input").css('display','none');
  295. parent.find(".rule-date-type").remove();
  296. parent.find(".rule-date-passed").remove();
  297. }
  298. if ((filter_select == "Were sent [message]" || filter_select == "Were sent current campaign" || filter_select == "Were not sent current campaign" || filter_select == "Activate raw profile") && parent.find(".rule-email-container input").val() == undefined) {
  299. parent.find(".rule-operator-container span").remove();
  300. parent.find(".rule-email-container span").remove();
  301. if(filter_select == "Were sent [message]") {
  302. parent.find(".rule-email-container").append("<input placeholder='Please enter email' class='form-control form-email_id inputbox' required/><span> at least</span>");
  303. }else if (filter_select == "Were sent current campaign"){
  304. parent.find(".rule-email-container").append("<span> current campaign at least</span>");
  305. }else if (filter_select == "Were not sent current campaign"){
  306. parent.find(".rule-email-container").append("<span> current campaign </span>");
  307. }else if (filter_select == "Activate raw profile"){
  308. parent.find(".rule-email-container").append("<span> Activate raw profile </span>");
  309. }
  310. parent.find(".rule-operator-container").css({
  311. "width": "0",
  312. "opacity": "0"
  313. });
  314. parent.find(".rule-operator-container select").css("width", "0");
  315. }
  316. if (filter_select == "Were sent [message]" || filter_select== "Were sent current campaign" || filter_select== "Were not sent current campaign" || filter_select== "Activate raw profile") {
  317. parent.find(".rule-operator-container span").remove();
  318. filterText = filter_select = parent.find(".rule-filter-container select option:checked").text();
  319. if(filter_select == "Were sent [message]") {
  320. filterText = filterText.replace(filterText.substr(filterText.indexOf("[message]")), "");
  321. }else if(filter_select == "Were sent current campaign"){
  322. filterText = filterText.replace(filterText.substr(filterText.indexOf("current")), "");
  323. }else if(filter_select == "Were not sent current campaign"){
  324. filterText = filterText.replace(filterText.substr(filterText.indexOf("current")), "");
  325. }
  326. if(filter_select != "Activate raw profile") {
  327. parent.find(".rule-filter-container select").css("color", "#191919");
  328. parent.find(".rule-filter-container span").remove();
  329. parent.find(".rule-filter-container").append("<span class='filter-text'>" + filterText + "</span>");
  330. }
  331. } else {
  332. parent.find(".rule-email-container input").remove();
  333. parent.find(".rule-email-container span").remove();
  334. parent.find(".rule-operator-container").css({
  335. "width": "135px",
  336. "opacity": "1"
  337. });
  338. parent.find(".rule-operator-container select").css("width", "auto");
  339. }
  340. }
  341. }
  342. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement