Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $("#builder").queryBuilder({
- filters: [{
- id: "Status",
- input: "select",
- multiple: true,
- operators: ["in"],
- default_value: 'SbscStSubscriberOptIn',
- values: {
- SbscStSubscriberOptIn: "SubscriberOptIn",
- SbscStSubscriberDoubleOptIn: "SubscriberDoubleOptIn",
- SbscStActivatedOpener: "ActivatedOpener",
- SbscStActivatedClicker: "ActivatedClicker"
- }
- },{
- id: "ISP",
- input: "select",
- multiple: true,
- operators: ["in", "not_in"],
- default_value: 'Google',
- values: {
- Google: "Gmail",
- Yahoo: "Yahoo",
- Hotmail: "Hotmail",
- Aol: "Aol"
- }
- },/*{
- id: "Activate raw profile",
- input: "text",
- type: "string",
- operators: ["equal"],
- default_value: 0,
- validation: {
- min: 0
- }
- }, */{
- id: "Last activity date",
- input: "text",
- operators: ["not_equal",'less', 'greater', 'equal','less_or_equal','greater_or_equal'],
- unique: true
- }, {
- id: "Registration date",
- type: "date",
- operators: ["not_equal",'less', 'greater', 'equal','less_or_equal','greater_or_equal'],
- unique: true
- }, {
- id: "Were sent current campaign",
- input: "text",
- type: "string",
- operators: ["not_equal"],
- validation: {
- min: 0
- }
- }
- /*, {
- id: "Were not sent current campaign",
- input: "text",
- type: "string",
- operators: ["equal"],
- default_value: 0,
- validation: {
- min: 0
- }
- }, {
- id: "Were sent [message]",
- input: "text",
- type: "string",
- operators: ["not_equal"],
- validation: {
- min: 0
- }
- }*/
- ]
- });
- $(".group-conditions:first").append("<a class='btn big' onclick='$(\"#builder\").queryBuilder(\"reset\");return false;'>Reset</a>");
- function parseJson(result) {
- var operator = {
- "is later than": "greater",
- "is earlier than": "less",
- "is more than x days/months/years passed": "less",
- "in": "equal",
- "not_in": "notequal",
- "is equal": "equal",
- "is exactly x days/months/years passed": "equal",
- "Were sent [message]" : "less",
- "Were sent current campaign" : "less",
- "Were not sent current campaign" : "less"
- };
- var id = {
- "Status": "SentRuleConditionByProfileStatus",
- "ISP": "SentRuleConditionByISP",
- "Activate raw profile": "SendRuleActivateRawProfile",
- "Last activity date": "SentRuleConditionByLastActionDate",
- "Registration date": "SentRuleConditionByRegDate",
- "Were sent [message]": "SentRuleConditionByLastSentDate",
- "Were sent current campaign": "SentRuleConditionByLastSentDate",
- "Were not sent current campaign": "SentRuleConditionByLastSentDate"
- };
- var converterType = {
- "Days": "SentRuleDateConverterDaysAgo",
- "Date": "SentRuleDateConverterDate"
- };
- var final = {};
- final["Condition"] = [];
- if (!result["rules"])
- return final;
- for (var j = 0; j < result["rules"].length; j++) {
- var re = {};
- var converterValue = {};
- var converter = "";
- var condition = {};
- var operatorText = "";
- for (var i in result["rules"][j]) {
- if (result["rules"][j]["id"] == "Status") {
- re["AllowedStatuses"] = result["rules"][j]["value"];
- condition["ConditionType"] = id[result["rules"][j]["id"]];
- } else if (result["rules"][j]["id"] == "ISP") {
- re["AllowedISPs"] = result["rules"][j]["value"];
- condition["ConditionType"] = id[result["rules"][j]["id"]];
- if (i == "operator") {
- re["Operation"] = operator[result["rules"][j]["operator"]];
- }
- } else if (result["rules"][j]["id"] == "Activate raw profile") {
- condition["ConditionType"] = id[result["rules"][j]["id"]];
- } else if (i == "id") {
- condition["ConditionType"] = id[result["rules"][j][i]];
- } else if (i == "operator") {
- var len = parseInt($(".rule-container:last").attr("id").replace(/[^-0-9]/gim, ""));
- for (var k = 0; k < $(".rule-filter-container").length + len; k++) {
- var filter = $(".rule-filter-container select[name='builder_rule_" + k + "_filter']");
- var filterChecked = $(".rule-filter-container select[name='builder_rule_" + k + "_filter'] option:checked").text();
- var value = $(".rule-value-container input[name='builder_rule_" + k + "_value_0']");
- if (value.val() == result["rules"][j]["value"] && filter.val() == result["rules"][j]["id"]) {
- operatorText = filter.parent(".rule-filter-container").parent(".rule-container").find(".rule-operator-container select option:checked").text();
- converter = filter.parent(".rule-filter-container").parent(".rule-container").find(".rule-value-container select.rule-date-type").val();
- 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") {
- re["Operation"] = operator[filterChecked];
- if(result["rules"][j]["id"] != "Were sent [message]"){
- re["EmailId"] = parseInt($('input[name="emailId"]').val())
- }
- } else {
- re["Operation"] = operator[operatorText];
- }
- if (result["rules"][j]["id"] == "Were sent [message]") {
- re["EmailId"] = parseInt(filter.parent(".rule-filter-container").parent(".rule-container").find(".rule-email-container input").val())
- }
- }
- }
- } else if (i == "value") {
- if (converter == "Days") {
- converterValue[converter] = parseInt(result["rules"][j][i]);
- re["ConverterType"] = converterType[converter];
- } else {
- if(result["rules"][j]["id"] == "Were not sent current campaign"){
- converterValue["Date"] = 1;
- }else {
- var explode_date = result["rules"][j][i].split('/');
- var date_reform = explode_date[1] + '/' + explode_date[0] + '/' + explode_date[2];
- var dateObject = new Date(Date.UTC(explode_date[2], explode_date[1] - 1, explode_date[0]));
- var timestamp = dateObject.valueOf();
- timestamp = String(timestamp);
- timestamp = timestamp.substring(0, timestamp.length - 3);
- timestamp = parseInt(timestamp);
- converterValue["Date"] = timestamp;
- }
- re["ConverterType"] = converterType["Date"];
- }
- re["Converter"] = converterValue;
- }
- }
- condition["Condition"] = re;
- if (result["condition"] == "AND") {
- final["ConditionType"] = "SentRuleConditionAnd";
- } else if (result["condition"] == "OR") {
- final["ConditionType"] = "SentRuleConditionOr";
- }
- if (result["rules"][j]["id"]) {
- final["Condition"].push(condition);
- }
- }
- return final;
- }
- $(".query-builder").on("click", function() {
- setTimeout(refreshBuilder,0);
- });
- function refreshBuilder() {
- var rules = $(".rules-group-body .rules-list li");
- 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"};
- var len = parseInt($(".rule-container:last").attr("id").replace(/[^-0-9]/gim, ''));
- var operatorText = "";
- var filterText = "";
- for (var j = 0; j <= len; j++) {
- var value = $(".rule-value-container input[name='builder_rule_" + j + "_value_0']");
- var filter = $(".rule-filter-container select[name='builder_rule_" + j + "_filter']");
- if (value.val() == undefined) {
- var value = $(".rule-value-container select[name='builder_rule_" + j + "_value_0']");
- var parent = value.parent(".multiselect").parent(".rule-value-container").parent(".rule-container");
- var filterParent = filter.parent(".rule-filter-container");
- filterParent.find("span").remove();
- filterParent.find("select").css("color", "#fff");
- parent.find(".rule-email-container input").remove();
- parent.find(".rule-email-container span").remove();
- //parent.find(".rule-operator-container").css({
- // "width": "0",
- // "opacity": "0"
- //});
- //parent.find(".rule-operator-container select").css("width", "0");
- //if (parent.find(".rule-filter-container span").length == 0) {
- // parent.find(".rule-filter-container").append("<span> IN </span>");
- //}
- parent.find(".rule-operator-container").css({
- "width": "auto",
- "opacity": "1"
- });
- if (value.parent(".multiselect").find(".select2-hidden-accessible").length == 0 && value.parent(".multiselect").length > 0) {
- $(".select-2").select2();
- }
- } else {
- var parent = value.parent(".rule-value-container").parent(".rule-container");
- var operator = parent.find(".rule-operator-container select option:checked").text();
- var operator_val = parent.find(".rule-operator-container select option:checked").val();
- var filter_select = parent.find(".rule-filter-container select").val();
- parent.find(".rule-filter-container span").remove();
- parent.find(".rule-filter-container select").css("color", "#fff");
- 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)) {
- parent.find(".rule-operator-container select").find("option").remove().end()
- for (var i in selectValues) {
- if(operator_val == selectValues[i]){
- parent.find(".rule-operator-container select").append("<option value='" + selectValues[i] + "' selected>" + i + "</option>");
- }else {
- parent.find(".rule-operator-container select").append("<option value='" + selectValues[i] + "'>" + i + "</option>");
- }
- }
- }
- if (operator.length > 0) {
- operatorText = parent.find(".rule-operator-container select option:checked").text();
- parent.find(".rule-operator-container span").remove();
- parent.find(".rule-operator-container").append("<span class='operator-text'>" + operatorText + "</span>");
- parent.find(".rule-operator-container select").css({
- "z-index": 9,
- "position": 'absolute',
- "top": 10,
- "opacity": 0.6,
- "color": '#191919'
- });
- }
- if (operator == "is later than" || operator == "is earlier than" || operator == "is later or equal" || operator == "is earlier or equal" || operator == "is equal") {
- parent.find(".rule-date-type").remove();
- parent.find(".rule-date-passed").remove();
- parent.find(".rule-value-container input").css('display','inherit');
- parent.find(".rule-operator-container").css({
- "width": "0",
- "opacity": "0"
- });
- parent.find(".rule-operator-container select").css("width", "0");
- if (parent.find(".rule-value-container .input-group-addon").length == 0) {
- value.attr("id", "datepicker_" + j)
- }
- $("#datepicker_" + j).datepicker({ dateFormat: 'dd/mm/yy' })
- } 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") {
- if (parent.find(".rule-value-container .hasDatepicker").length > 0) {
- $("#datepicker_" + j).datepicker("hide")
- }
- if (parent.find(".rule-date-type").val() == undefined) {
- 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>");
- }
- parent.find(".rule-value-container input").css('display','inherit');
- operatorText = parent.find(".rule-operator-container select option:checked").text();
- operatorText = operatorText.replace(operatorText.substr(operatorText.indexOf(" x ")), "");
- parent.find(".rule-operator-container span").remove();
- parent.find(".rule-operator-container").append("<span class='operator-text'>" + operatorText + "</span>");
- parent.find(".rule-operator-container select").css({
- "z-index": 9,
- "position": 'absolute',
- "top": 10,
- "opacity": 0.6,
- "color": '#191919'
- });
- if (value.val() != undefined) {
- if (value.val().indexOf("2015") >= 0)
- value.val("")
- }
- } else {
- parent.find(".rule-value-container input").css('display','none');
- parent.find(".rule-date-type").remove();
- parent.find(".rule-date-passed").remove();
- }
- 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) {
- parent.find(".rule-operator-container span").remove();
- parent.find(".rule-email-container span").remove();
- if(filter_select == "Were sent [message]") {
- parent.find(".rule-email-container").append("<input placeholder='Please enter email' class='form-control form-email_id inputbox' required/><span> at least</span>");
- }else if (filter_select == "Were sent current campaign"){
- parent.find(".rule-email-container").append("<span> current campaign at least</span>");
- }else if (filter_select == "Were not sent current campaign"){
- parent.find(".rule-email-container").append("<span> current campaign </span>");
- }else if (filter_select == "Activate raw profile"){
- parent.find(".rule-email-container").append("<span> Activate raw profile </span>");
- }
- parent.find(".rule-operator-container").css({
- "width": "0",
- "opacity": "0"
- });
- parent.find(".rule-operator-container select").css("width", "0");
- }
- 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-operator-container span").remove();
- filterText = filter_select = parent.find(".rule-filter-container select option:checked").text();
- if(filter_select == "Were sent [message]") {
- filterText = filterText.replace(filterText.substr(filterText.indexOf("[message]")), "");
- }else if(filter_select == "Were sent current campaign"){
- filterText = filterText.replace(filterText.substr(filterText.indexOf("current")), "");
- }else if(filter_select == "Were not sent current campaign"){
- filterText = filterText.replace(filterText.substr(filterText.indexOf("current")), "");
- }
- if(filter_select != "Activate raw profile") {
- parent.find(".rule-filter-container select").css("color", "#191919");
- parent.find(".rule-filter-container span").remove();
- parent.find(".rule-filter-container").append("<span class='filter-text'>" + filterText + "</span>");
- }
- } else {
- parent.find(".rule-email-container input").remove();
- parent.find(".rule-email-container span").remove();
- parent.find(".rule-operator-container").css({
- "width": "135px",
- "opacity": "1"
- });
- parent.find(".rule-operator-container select").css("width", "auto");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement