Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.HttpMethod != "POST")
            {
                return;
            }

            String area = "";

            if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"]))
            {
                area = (String)RouteData.Values["area"];
            }

            Int64 enterpriseId = 0;

            if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData))
            {
                enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id;
            }

            Boolean newItem = false;

            if ((RouteData.Values["new"] != null) && (RouteData.Values["new"] == "1"))
            {
                newItem = true;
            }

            String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString();

            LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/");
            LMenu menu2 = new LMenu("Filtros", ApplicationVirtualPath + "admin/filter/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : ""));
            LMenu menu3 = new LMenu("Filtros", ApplicationVirtualPath + "admin/filter/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : ""));

            WebJsonResponse contentRet = null;

            String html  = "";
            String eHtml = "";
            String js    = null;

            String errorTemplate = "<span class=\"empty-results\">{0}</span>";

            //Verifica se está sendo selecionada uma role
            Int64 filterId = 0;

            try
            {
                filterId = Int64.Parse((String)RouteData.Values["id"]);

                if (filterId < 0)
                {
                    filterId = 0;
                }
            }
            catch { }

            String          error     = "";
            FilterGetResult retFilter = null;
            String          filter    = "";
            HashData        hashData  = new HashData(this);

            String rData = null;
            //SqlConnection conn = null;
            String jData = "";

            Int32   page     = 1;
            Int32   pageSize = 20;
            Boolean hasNext  = true;

            if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"]))
            {
                filter = (String)RouteData.Values["filter"];
            }

            if ((filterId > 0) && (area.ToLower() != "search"))
            {
                try
                {
                    rData = SafeTrend.Json.JSON.Serialize2(new
                    {
                        jsonrpc    = "1.0",
                        method     = "filter.get",
                        parameters = new
                        {
                            filterid = filterId
                        },
                        id = 1
                    });
                    jData = "";
                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString()))
                        jData = WebPageAPI.ExecuteLocal(database, this, rData);


                    if (String.IsNullOrWhiteSpace(jData))
                    {
                        throw new Exception("");
                    }

                    retFilter = JSON.Deserialize <FilterGetResult>(jData);
                    if (retFilter == null)
                    {
                        error = MessageResource.GetMessage("filter_not_found");
                        //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true);
                    }
                    else if (retFilter.error != null)
                    {
                        error     = retFilter.error.data;
                        retFilter = null;
                    }
                    else if (retFilter.result == null || retFilter.result.info == null)
                    {
                        error     = MessageResource.GetMessage("filter_not_found");
                        retFilter = null;
                    }
                    else
                    {
                        menu3.Name = retFilter.result.info.name;
                    }
                }
                catch (Exception ex)
                {
                    error = MessageResource.GetMessage("api_error");
                    Tools.Tool.notifyException(ex, this);
                    retFilter = null;
                    //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true);
                }
            }

            String infoTemplate = "<tr><td class=\"col1\">{0}</td><td class=\"col2\"><span class=\"no-edit\">{1}</span></td></tr>";

            String groupTemplate          = "<div id=\"{0}\"><div class=\"group\" group-id=\"{0}\"><div class=\"wrapper\"><div class=\"cmd-bar\"><div class=\"ico icon-close floatright\"></div></div>{1}<div class=\"cmd-bar1\"><div class=\"ico icon-plus floatright\"></div></div></div><div class=\"clear-block\"></div></div><div class=\"selector-wrapper\">{2}</div></div>";
            String groupSelectorTemplate  = "<div class=\"group-selector\"><select type=\"checkbox\" name=\"group_{0}_selector\"><option value=\"or\" {1}>or</option><option value=\"and\" {2}>and</option></select><div class=\"item {1}\" value=\"or\">OU</div><div class=\"item {2}\" value=\"and\">E</div><div class=\"clear-block\"></div></div>";
            String filterSelectorTemplate = "<div class=\"filter-selector\"><select type=\"checkbox\" name=\"filter_{0}_selector\"><option value=\"or\" {1}>or</option><option value=\"and\" {2}>and</option></select> <div class=\"item {1}\" value=\"or\">OU</div><div class=\"item {2}\" value=\"and\">E</div><div class=\"clear-block\"></div></div>";


            switch (area)
            {
            case "":
            case "search":
            case "content":
                if (newItem)
                {
                    rData = SafeTrend.Json.JSON.Serialize2(new
                    {
                        jsonrpc    = "1.0",
                        method     = "field.list",
                        parameters = new
                        {
                            page_size = Int32.MaxValue
                        },
                        id = 1
                    });
                    jData = "";
                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString()))
                        jData = WebPageAPI.ExecuteLocal(database, this, rData);

                    List <FieldData> fieldList = new List <FieldData>();
                    FieldListResult  flR       = JSON.Deserialize <FieldListResult>(jData);
                    if ((flR != null) && (flR.error == null) && (flR.result != null))
                    {
                        fieldList = flR.result;
                    }

                    String filterTemplate = GetFilterTemplate(fieldList, 0, "", "");

                    html  = "<h3>Adição do filtro</h3>";
                    html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/filter/action/add_filter/\">";
                    html += "<div class=\"no-tabs fields\"><table><tbody>";
                    html += String.Format(infoTemplate, "Nome", "<input id=\"filter_name\" name=\"filter_name\" placeholder=\"Digite o nome do filtro\" type=\"text\"\">");
                    html += "</tbody></table><div class=\"clear-block\"></div></div>";

                    html += "<h3>Parametros de filtragem</h3><div class=\"no-tabs pb10\">";
                    html += "<div id=\"filter_conditions\"><div><div class=\"a-btn blue secondary\" onclick=\"iamfnc.addGroup();\">Inserir grupo</div></div>";
                    html += "<div class=\"filter-groups\">";


                    String filters = String.Format(filterTemplate, "F0", "0", "");
                    html += String.Format(groupTemplate, "0", filters, "");

                    html += "</div>";

                    html += "</div><div class=\"clear-block\"></div></div>";
                    html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button>    <a href=\"" + ApplicationVirtualPath + "admin/filter/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>";

                    contentRet    = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html));
                    contentRet.js = GetFilterJS(groupTemplate, groupSelectorTemplate, filterTemplate, filterSelectorTemplate);
                }
                else
                {
                    if (retFilter == null)
                    {
                        Int32.TryParse(Request.Form["page"], out page);

                        if (page < 1)
                        {
                            page = 1;
                        }

                        String proxyTemplate = "<div id=\"proxy-list-{0}\" data-id=\"{0}\" data-name=\"{1}\" data-total=\"{2}\" class=\"app-list-item\">";
                        proxyTemplate += "<table>";
                        proxyTemplate += "   <tbody>";
                        proxyTemplate += "       <tr>";
                        proxyTemplate += "           <td class=\"col1\">";
                        proxyTemplate += "               <span id=\"total_{0}\" class=\"total \">{2}</span>";
                        proxyTemplate += "               <a href=\"" + ApplicationVirtualPath + "admin/filter/{0}/use/\">";
                        proxyTemplate += "                   <div class=\"app-btn a-btn\"><span class=\"a-btn-inner\">Ver utilizações</span></div>";
                        proxyTemplate += "               </a>";
                        proxyTemplate += "           </td>";
                        proxyTemplate += "           <td class=\"col2\">";
                        proxyTemplate += "               <div class=\"title\"><span class=\"name field-editor\" id=\"filter_name_{0}\" data-id=\"{0}\" data-function=\"iamadmin.editTextField('#filter_name_{0}',null,filterNameEdit);\">{1}</span><span class=\"date\">{3}</span><div class=\"clear-block\"></div></div>";
                        proxyTemplate += "               <div class=\"description\">";
                        proxyTemplate += "                   <div class=\"first\">{4}</div>";
                        proxyTemplate += "               </div>";
                        proxyTemplate += "               <div class=\"links\">";
                        proxyTemplate += "                   <div class=\"last\">{5}</div>";
                        proxyTemplate += "               </div>";
                        proxyTemplate += "           </td>";
                        proxyTemplate += "       </tr>";
                        proxyTemplate += "   </tbody>";
                        proxyTemplate += "</table></div>";

                        js += "filterNameEdit = function(thisId, changedText) { iamadmin.changeName(thisId,changedText); };";

                        html += "<div id=\"box-container\" class=\"box-container\">";

                        String query = "";
                        try
                        {
                            rData = "";

                            if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"]))
                            {
                                query = (String)RouteData.Values["query"];
                            }

                            if (String.IsNullOrWhiteSpace(query) && !String.IsNullOrWhiteSpace(hashData.GetValue("query")))
                            {
                                query = hashData.GetValue("query");
                            }

                            if (String.IsNullOrWhiteSpace(query))
                            {
                                rData = SafeTrend.Json.JSON.Serialize2(new
                                {
                                    jsonrpc    = "1.0",
                                    method     = "filter.list",
                                    parameters = new
                                    {
                                        page_size = pageSize,
                                        page      = page
                                    },
                                    id = 1
                                });
                            }
                            else
                            {
                                rData = SafeTrend.Json.JSON.Serialize2(new
                                {
                                    jsonrpc    = "1.0",
                                    method     = "filter.search",
                                    parameters = new
                                    {
                                        text      = query,
                                        page_size = pageSize,
                                        page      = page
                                    },
                                    id = 1
                                });
                            }

                            jData = "";
                            using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString()))
                                jData = WebPageAPI.ExecuteLocal(database, this, rData);

                            if (String.IsNullOrWhiteSpace(jData))
                            {
                                throw new Exception("");
                            }

                            FilterListResult ret2 = JSON.Deserialize <FilterListResult>(jData);
                            if (ret2 == null)
                            {
                                eHtml  += String.Format(errorTemplate, MessageResource.GetMessage("filter_not_found"));
                                hasNext = false;
                            }
                            else if (ret2.error != null)
                            {
#if DEBUG
                                eHtml += String.Format(errorTemplate, ret2.error.data + ret2.error.debug);
#else
                                eHtml += String.Format(errorTemplate, ret2.error.data);
#endif
                                hasNext = false;
                            }
                            else if (ret2.result == null || (ret2.result.Count == 0 && page == 1))
                            {
                                eHtml  += String.Format(errorTemplate, MessageResource.GetMessage("filter_not_found"));
                                hasNext = false;
                            }
                            else
                            {
                                foreach (FilterData f in ret2.result)
                                {
                                    String text = "<span>" + f.conditions_description + "</span>";

                                    String links = "";
                                    links += "<a href=\"" + ApplicationVirtualPath + "admin/filter/" + f.filter_id + "/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-change\">Editar</div></a>";
                                    links += (f.ignore_qty > 0 || f.lock_qty > 0 || f.role_qty > 0 ? "" : "<a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/filter/" + f.filter_id + "/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente o filtro '" + f.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Apagar</div></a>");

                                    html += String.Format(proxyTemplate, f.filter_id, f.name, f.ignore_qty + f.lock_qty + f.role_qty, (f.create_date > 0 ? "Criado em " + MessageResource.FormatDate(new DateTime(1970, 1, 1).AddSeconds(f.create_date), true) : ""), text, links);
                                }

                                if (ret2.result.Count < pageSize)
                                {
                                    hasNext = false;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error"));
                        }

                        if (page == 1)
                        {
                            html += "</div>";

                            html += "<span class=\"empty-results content-loading proxy-list-loader hide\"></span>";

                            contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html));
                        }
                        else
                        {
                            contentRet = new WebJsonResponse("#content-wrapper #box-container", (eHtml != "" ? eHtml : html), true);
                        }

                        contentRet.js = js + "$( document ).unbind('end_of_scroll');";

                        if (hasNext)
                        {
                            contentRet.js += "$( document ).bind( 'end_of_scroll.loader_role', function() { $( document ).unbind('end_of_scroll.loader_role'); $('.proxy-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'" + (!String.IsNullOrWhiteSpace(query) ? query : "") + "' }, function(){ $('.proxy-list-loader').addClass('hide'); } ); });";
                        }
                    }
                    else    //Esta sendo selecionado o filtro
                    {
                        if (error != "")
                        {
                            contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error));
                        }
                        else
                        {
                            switch (filter)
                            {
                            case "":

                                rData = SafeTrend.Json.JSON.Serialize2(new
                                {
                                    jsonrpc    = "1.0",
                                    method     = "field.list",
                                    parameters = new
                                    {
                                        page_size = Int32.MaxValue
                                    },
                                    id = 1
                                });
                                jData = "";
                                using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString()))
                                    jData = WebPageAPI.ExecuteLocal(database, this, rData);

                                List <FieldData> fieldList = new List <FieldData>();
                                FieldListResult  flR       = JSON.Deserialize <FieldListResult>(jData);
                                if ((flR != null) && (flR.error == null) && (flR.result != null))
                                {
                                    fieldList = flR.result;
                                }


                                String filterTemplate = GetFilterTemplate(fieldList, 0, "", "");

                                html  = "<h3>Edição do filtro</h3>";
                                html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/filter/" + retFilter.result.info.filter_id + "/action/change/\">";
                                html += "<div class=\"no-tabs fields\"><table><tbody>";
                                html += String.Format(infoTemplate, "Nome", "<input id=\"filter_name\" name=\"filter_name\" placeholder=\"Digite o nome do filtro\" type=\"text\"\" value=\"" + retFilter.result.info.name + "\">");
                                html += "</tbody></table><div class=\"clear-block\"></div></div>";

                                html += "<h3>Parametros de filtragem</h3><div class=\"no-tabs pb10\">";
                                html += "<div id=\"filter_conditions\"><div><div class=\"a-btn blue secondary\" onclick=\"iamfnc.addGroup();\">Inserir grupo</div></div>";
                                html += "<div class=\"filter-groups\">";

                                FilterRule fr = new FilterRule(retFilter.result.info.name);
                                foreach (IAM.GlobalDefs.WebApi.FilterCondition cond in retFilter.result.info.conditions)
                                {
                                    fr.AddCondition(cond.group_id.ToString(), cond.group_selector, cond.field_id, cond.field_name, cond.data_type, cond.text, cond.condition, cond.selector);
                                }

                                for (Int32 g = 0; g < fr.FilterGroups.Count; g++)
                                {
                                    String filters = "";

                                    for (Int32 fIndex = 0; fIndex < fr.FilterGroups[g].FilterRules.Count; fIndex++)
                                    {
                                        String fId = fr.FilterGroups[g].GroupId + "-" + fIndex;

                                        String ft = GetFilterTemplate(fieldList, fr.FilterGroups[g].FilterRules[fIndex].FieldId, fr.FilterGroups[g].FilterRules[fIndex].DataString, fr.FilterGroups[g].FilterRules[fIndex].ConditionType.ToString());

                                        filters += String.Format(ft, fId, fr.FilterGroups[g].GroupId, (fIndex < fr.FilterGroups[g].FilterRules.Count - 1 ? (fr.FilterGroups[g].FilterRules[fIndex].Selector == FilterSelector.AND ? String.Format(filterSelectorTemplate, fId, "", "selected") : String.Format(filterSelectorTemplate, fId, "selected", "")) : ""));
                                    }

                                    html += String.Format(groupTemplate, fr.FilterGroups[g].GroupId, filters, (g < fr.FilterGroups.Count - 1 ? (fr.FilterGroups[g].Selector == FilterSelector.AND ? String.Format(groupSelectorTemplate, fr.FilterGroups[g].GroupId, "", "selected") : String.Format(groupSelectorTemplate, fr.FilterGroups[g].GroupId, "selected", "")) : ""));
                                }

                                html += "</div>";

                                html += "</div><div class=\"clear-block\"></div></div>";
                                html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button>    <a href=\"" + ApplicationVirtualPath + "admin/filter/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>";

                                contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html));

                                contentRet.js = GetFilterJS(groupTemplate, groupSelectorTemplate, filterTemplate, filterSelectorTemplate);

                                break;

                            case "use":
                                if (retFilter != null)
                                {
                                    Int32.TryParse(Request.Form["page"], out page);

                                    if (page < 1)
                                    {
                                        page = 1;
                                    }

                                    if (page == 1)
                                    {
                                        html  = "<h3>Utilização deste perfil</h3>";
                                        html += "<table id=\"users-table\" class=\"sorter\"><thead>";
                                        html += "    <tr>";
                                        html += "        <th class=\"w50 mHide {sorter: false}\"><div class=\"select-all\"></div></th>";
                                        html += "        <th class=\"pointer header headerSortDown\" data-column=\"name\">Recurso x Plugin <div class=\"icomoon\"></div></th>";
                                        html += "        <th class=\"pointer tHide mHide header\" data-column=\"login\">Bloqueio <div class=\"icomoon\"></div></th>";
                                        html += "        <th class=\"pointer tHide mHide header\" data-column=\"login\">Vínculo com perfil <div class=\"icomoon\"></div></th>";
                                        html += "        <th class=\"pointer tHide mHide header\" data-column=\"login\">Desconsiderar registros <div class=\"icomoon\"></div></th>";
                                        html += "        <th class=\"pointer w200 tHide mHide header\" data-column=\"last_login\">Ações <div class=\"icomoon\"></div></th>";
                                        html += "    </tr>";
                                        html += "</thead>";

                                        html += "<tbody>";
                                    }

                                    String trTemplate = "    <tr class=\"user\" data-userid=\"{0}\">";
                                    trTemplate += "            <td class=\"select mHide\"><div class=\"checkbox\"></div></td>";
                                    trTemplate += "            <td class=\"ident10\">{2}</td>";
                                    trTemplate += "            <td class=\"tHide mHide\">{3}</td>";
                                    trTemplate += "            <td class=\"tHide mHide\">{4}</td>";
                                    trTemplate += "            <td class=\"tHide mHide\">{5}</td>";
                                    trTemplate += "            <td class=\"tHide mHide\"><button class=\"a-btn\" onclick=\"window.location = '" + ApplicationVirtualPath + "admin/resource_plugin/{1}/';\">Abrir</button></td>";
                                    trTemplate += "    </tr>";

                                    try
                                    {
                                        rData = SafeTrend.Json.JSON.Serialize2(new
                                        {
                                            jsonrpc    = "1.0",
                                            method     = "filter.use",
                                            parameters = new
                                            {
                                                page_size = pageSize,
                                                page      = page,
                                                filterid  = retFilter.result.info.filter_id
                                            },
                                            id = 1
                                        });

                                        jData = "";
                                        using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString()))
                                            jData = WebPageAPI.ExecuteLocal(database, this, rData);

                                        if (String.IsNullOrWhiteSpace(jData))
                                        {
                                            throw new Exception("");
                                        }

                                        FilterUseResult ret2 = JSON.Deserialize <FilterUseResult>(jData);
                                        if (ret2 == null)
                                        {
                                            eHtml += String.Format(errorTemplate, MessageResource.GetMessage("filter_not_found"));
                                            //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true);
                                            hasNext = false;
                                        }
                                        else if (ret2.error != null)
                                        {
                                            eHtml += String.Format(errorTemplate, ret2.error.data);
                                            //ret = new WebJsonResponse("", ret2.error.data, 3000, true);
                                            hasNext = false;
                                        }
                                        else if (ret2.result == null || (ret2.result.Count == 0 && page == 1))
                                        {
                                            eHtml  += String.Format(errorTemplate, MessageResource.GetMessage("filter_not_found"));
                                            hasNext = false;
                                        }
                                        else
                                        {
                                            foreach (FilterUseData f in ret2.result)
                                            {
                                                html += String.Format(trTemplate, f.filter_id, f.resource_plugin_id, f.resource_plugin_name, f.lock_qty, f.role_qty, f.ignore_qty);
                                            }

                                            if (ret2.result.Count < pageSize)
                                            {
                                                hasNext = false;
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error"));
                                        //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true);
                                    }

                                    if (page == 1)
                                    {
                                        html += "</tbody></table>";

                                        html += "<span class=\"empty-results content-loading user-list-loader hide\"></span>";

                                        contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html));
                                    }
                                    else
                                    {
                                        contentRet = new WebJsonResponse("#content-wrapper tbody", (eHtml != "" ? eHtml : html), true);
                                    }

                                    contentRet.js = "$( document ).unbind('end_of_scroll.loader_usr');";

                                    if (hasNext)
                                    {
                                        contentRet.js += "$( document ).bind( 'end_of_scroll.loader_usr', function() { $( document ).unbind('end_of_scroll.loader_usr'); $('.user-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'' }, function(){ $('.user-list-loader').addClass('hide'); } ); });";
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
                break;



            case "sidebar":
                if (menu1 != null)
                {
                    html += "<div class=\"sep\"><div class=\"section-nav-header\">";
                    html += "    <div class=\"crumbs\">";
                    html += "        <div class=\"subject subject-color\">";
                    html += "            <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>";
                    html += "        </div>";
                    if (menu2 != null)
                    {
                        html += "        <div class=\"topic topic-color\">";
                        html += "            <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>";
                        html += "        </div>";
                    }
                    html += "    </div>";
                    if (menu3 != null)
                    {
                        html += "    <div class=\"crumbs tutorial-title\">";
                        html += "        <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>";
                        html += "    </div>";
                    }
                    html += "</div></div>";
                }

                if (!newItem)
                {
                    html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/filter/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo filtro</button></div>";
                }

                contentRet = new WebJsonResponse("#main aside", html);
                break;

            case "mobilebar":
                break;


            case "buttonbox":
                break;
            }

            if (contentRet != null)
            {
                if (!String.IsNullOrWhiteSpace((String)Request["cid"]))
                {
                    contentRet.callId = (String)Request["cid"];
                }

                Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON()));
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            WebJsonResponse contentRet = null;


            String action = "";

            if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"]))
            {
                action = (String)RouteData.Values["action"];
            }

            Int64 filterId = 0;

            if (action != "add_filter")
            {
                try
                {
                    filterId = Int64.Parse((String)RouteData.Values["id"]);

                    if (filterId < 0)
                    {
                        filterId = 0;
                    }
                }
                catch { }

                if (filterId == 0)
                {
                    contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true);
                    action     = "";
                }
            }

            String rData = "";
            //SqlConnection //conn = DB.GetConnection();
            String jData = "";

            try
            {
                switch (action)
                {
                case "delete":

                    var reqDel = new
                    {
                        jsonrpc    = "1.0",
                        method     = "filter.delete",
                        parameters = new
                        {
                            filterid = filterId
                        },
                        id = 1
                    };

                    rData = JSON.Serialize2(reqDel);

                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData);

                    if (String.IsNullOrWhiteSpace(jData))
                    {
                        throw new Exception("");
                    }

                    FieldDeleteResult retDel = JSON.Deserialize <FieldDeleteResult>(jData);
                    if (retDel == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true);
                    }
                    else if (retDel.error != null)
                    {
                        contentRet = new WebJsonResponse("", retDel.error.data, 3000, true);
                    }
                    else if (!retDel.result)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true);
                    }
                    else
                    {
                        contentRet = new WebJsonResponse();
                    }
                    break;

                case "add_filter":

                    contentRet = null;
                    FilterRule newItem = GetFilterByForm(out contentRet);
                    if ((contentRet != null) || (newItem == null))
                    {
                        break;
                    }

                    rData = JSON.Serialize2(new
                    {
                        jsonrpc    = "1.0",
                        method     = "filter.new",
                        parameters = newItem.ToJsonObject(),
                        id         = 1
                    });

                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData);

                    if (String.IsNullOrWhiteSpace(jData))
                    {
                        throw new Exception("");
                    }

                    FilterGetResult retN = JSON.Deserialize <FilterGetResult>(jData);
                    if (retN == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true);
                    }
                    else if (retN.error != null)
                    {
                        contentRet = new WebJsonResponse("", retN.error.data, 3000, true);
                    }
                    else if (retN.result == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true);
                    }
                    else if (retN.result == null || retN.result.info == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true);
                    }
                    else
                    {
                        contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/filter/" + retN.result.info.filter_id + "/");
                    }
                    break;

                case "change":

                    contentRet = null;
                    FilterRule newItem1 = GetFilterByForm(out contentRet);
                    if ((contentRet != null) || (newItem1 == null))
                    {
                        break;
                    }

                    Dictionary <String, Object> par = newItem1.ToJsonObject();
                    par.Add("filterid", filterId);

                    rData = JSON.Serialize2(new
                    {
                        jsonrpc    = "1.0",
                        method     = "filter.change",
                        parameters = par,
                        id         = 1
                    });

                    using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData);

                    if (String.IsNullOrWhiteSpace(jData))
                    {
                        throw new Exception("");
                    }

                    FilterGetResult retC = JSON.Deserialize <FilterGetResult>(jData);
                    if (retC == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true);
                    }
                    else if (retC.error != null)
                    {
                        contentRet = new WebJsonResponse("", retC.error.data, 3000, true);
                    }
                    else if (retC.result == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true);
                    }
                    else if (retC.result == null || retC.result.info == null)
                    {
                        contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true);
                    }
                    else
                    {
                        contentRet             = new WebJsonResponse("", MessageResource.GetMessage("info_saved"), 3000, false);
                        contentRet.redirectURL = Session["ApplicationVirtualPath"] + "admin/filter/" + retC.result.info.filter_id + "/";
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true);
            }
            finally
            {
            }

            if (contentRet != null)
            {
                if (!String.IsNullOrWhiteSpace((String)Request["cid"]))
                {
                    contentRet.callId = (String)Request["cid"];
                }


                Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON()));
            }
        }