private void GetClick(object sender, RoutedEventArgs e) { if (login == null || String.IsNullOrEmpty(login.SessionID)) { AddMessage("Not logged in."); return; } string fct = Function.Text; try { string str = ID.Text; int id; if (!int.TryParse(str, out id)) { id = 0; } switch (fct) { case "GetGatewayHardwareIDs": IDResult gidr = api.GetGatewayHardwareIDs(login.SessionID, str); Done(fct, gidr, gidr.IDs); return; case "GetDeviceList": DeviceListResult dr = api.GetDeviceList(login.SessionID); Done(fct, dr, dr.DeviceList); return; case "GetDeviceListByID": if (String.IsNullOrWhiteSpace(str)) { return; } string[] ids = str.Split(','); int count = ids.Length; int[] pks = new int[count]; for (int i = 0; i < count; i++) { pks[i] = int.Parse(ids[i]); } DeviceListResult dlri = api.GetDeviceListByID(login.SessionID, pks); Done(fct, dlri, dlri.DeviceList); return; case "GetDeviceListByHFCandGwType (HFC,GwType)": DeviceListResult dlr = api.GetDeviceListFromHFCandGWType(login.SessionID, str); Done(fct, dlr, dlr.DeviceList); return; case "GetUserByName": UserResult sur = api.GetUserByName(login.SessionID, str); Done(fct, sur, sur.Data); return; case "GetUsersByEmail": IDResult eur = api.GetUsersByEmail(login.SessionID, str); Done(fct, eur, eur.IDs); return; case "GetLoggedInUser (session;ip)": string[] split = str.Split(';'); IDResult sir = api.GetLoggedInUser(login.SessionID, split[0], (split.Length > 1) ? split[1] : null); Done(fct, sir, sir.IDs); return; case "GetTimeZones": TimeZonesResult tz = api.GetTimeZones(login.SessionID, str); Done(fct, tz, tz.TimeZones); return; case "GetCustomer": if (id <= 0) { id = login.CustomerID; } CustomerResult cr = api.GetCustomer(login.SessionID, id); Done(fct, cr, cr.Data); return; case "GetChildCustomerIDs": if (id <= 0) { id = login.CustomerID; } IDResult cidr = api.GetChildCustomerIDs(login.SessionID, id); Done(fct, cidr, cidr.IDs); return; case "GetChildSiteIDs": if (id <= 0) { id = login.CustomerID; } IDResult csidr = api.GetChildSiteIDs(login.SessionID, id); Done(fct, csidr, csidr.IDs); return; case "GetChildUserIDs": if (id <= 0) { id = login.CustomerID; } IDResult cuidr = api.GetChildUserIDs(login.SessionID, id); Done(fct, cuidr, cuidr.IDs); return; case "GetUser": if (id <= 0) { id = login.UserID; } UserResult ur = api.GetUser(login.SessionID, id); Done(fct, ur, ur.Data); return; case "GetSite": SiteResult sr = api.GetSite(login.SessionID, id); Done(fct, sr, sr.Data); return; case "GetChildHardwareIDs": IDResult chidr = api.GetChildHardwareIDs(login.SessionID, id); Done(fct, chidr, chidr.IDs); return; case "GetChildGatewayIDs": IDResult cgidr = api.GetChildGatewayIDs(login.SessionID, id); Done(fct, cgidr, cgidr.IDs); return; case "GetChildInverterIDs": IDResult ciidr = api.GetChildInverterIDs(login.SessionID, id); Done(fct, ciidr, ciidr.IDs); return; case "GetHardware": HardwareResult hr = api.GetHardware(login.SessionID, id); Done(fct, hr, hr.Data); return; case "GetGateway": GatewayResult gr = api.GetGateway(login.SessionID, id); Done(fct, gr, gr.Data); return; case "GetInverter": InverterResult ir = api.GetInverter(login.SessionID, id); Done(fct, ir, ir.Data); return; case "GetStringCombiner": StringCombinerResult scr = api.GetStringCombiner(login.SessionID, id); Done(fct, scr, scr.Data); return; case "GetFieldList": FieldListResult fr = api.GetFieldList(login.SessionID, id); Done(fct, fr, fr.FieldList); return; } } catch { AddMessage(String.Concat(fct, " failed. Please check your connection.")); } }
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())); } }
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("Campos", ApplicationVirtualPath + "admin/field/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Campos", ApplicationVirtualPath + "admin/field/" + (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 fieldId = 0; try { fieldId = Int64.Parse((String)RouteData.Values["id"]); if (fieldId < 0) { fieldId = 0; } } catch { } String error = ""; FieldGetResult retField = null; String filter = ""; HashData hashData = new HashData(this); if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"])) { filter = (String)RouteData.Values["filter"]; } if ((fieldId > 0) && (area.ToLower() != "search")) { try { var tmpReq = new { jsonrpc = "1.0", method = "field.get", parameters = new { fieldid = fieldId }, id = 1 }; String rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } retField = JSON.Deserialize <FieldGetResult>(jData); if (retField == null) { error = MessageResource.GetMessage("field_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retField.error != null) { error = retField.error.data; retField = null; } else if (retField.result == null || retField.result.info == null) { error = MessageResource.GetMessage("field_not_found"); retField = null; } else { menu3.Name = retField.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); retField = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } switch (area) { case "": case "search": case "content": if (newItem) { html = "<h3>Adição de campo</h3>"; html += "<form id=\"form_add_resource\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/field/action/add_field/\"><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\"><label>Nome</label><input id=\"field_name\" name=\"field_name\" placeholder=\"Digite o nome do campo\" type=\"text\"\"></div>"; html += "<div class=\"form-group\"><label>Tipo de dado</label><select id=\"data_type\" name=\"data_type\" >"; html += "<option value=\"string\">Texto</option>"; html += "<option value=\"numeric\">Número</option>"; html += "<option value=\"datetime\">Data e Hora</option>"; html += "</select></div>"; html += "<div class=\"form-group\"><label>Público</label><input id=\"public\" name=\"public\" type=\"checkbox\"><span class=\"checkbox-label\">Permite visualização por todos os usuários</span></div>"; html += "<div class=\"form-group\"><label>Permite edição</label><input id=\"user\" name=\"user\" type=\"checkbox\"><span class=\"checkbox-label\">Permite que o usuário altere o valor</span></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"field-save\" class=\"button secondary floatleft\">Adicionar</button> <a href=\"" + ApplicationVirtualPath + "admin/field/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { if (retField == null) { Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } if (page == 1) { 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\">Campo <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Público <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Permite edição <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Tipo de dado <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-id=\"{0}\">"; trTemplate += " <td class=\"select mHide\"><div class=\"checkbox\"></div></td>"; trTemplate += " <td class=\"ident10\">{1}</td>"; trTemplate += " <td class=\"tHide mHide\">{2}</td>"; trTemplate += " <td class=\"tHide mHide\">{3}</td>"; trTemplate += " <td class=\"tHide mHide\">{4}</td>"; trTemplate += " <td class=\"tHide mHide\"><button class=\"a-btn\" onclick=\"window.location = '" + ApplicationVirtualPath + "admin/field/{0}/';\">Abrir</button> <button href=\"" + ApplicationVirtualPath + "admin/field/{0}/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"a-btn confirm-action\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente do campo '{1}'?\" ok=\"Excluir\" cancel=\"Cancelar\">Excluir</button></td>"; trTemplate += " </tr>"; try { String rData = ""; String query = ""; 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)) { var tmpReq = new { jsonrpc = "1.0", method = "field.list", parameters = new { page_size = pageSize, page = page }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } else { var tmpReq = new { jsonrpc = "1.0", method = "field.search", parameters = new { text = query, page_size = pageSize, page = page }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } FieldListResult ret2 = JSON.Deserialize <FieldListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("field_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("field_not_found")); hasNext = false; } else { foreach (FieldData field in ret2.result) { html += String.Format(trTemplate, field.field_id, field.name, (field.public_field ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no")), (field.user_field ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no")), MessageResource.GetMessage(field.data_type.ToLower())); } 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'); } ); });"; } } else //Esta sendo selecionado a role { if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } else { switch (filter) { case "": String infoTemplate = "<div class=\"form-group\">"; infoTemplate += "<label>{0}</label>"; infoTemplate += "<span class=\"no-edit\">{1}</span></div>"; String jsAdd = ""; if (hashData.GetValue("edit") == "1") { html += "<form id=\"form_resource_change\" method=\"POST\" action=\"" + ApplicationVirtualPath + "admin/field/" + retField.result.info.field_id + "/action/change/\">"; html += "<h3>Edição de campo</h3>"; html += "<div class=\"no-tabs pb10\">"; html += String.Format(infoTemplate, "Nome", "<input id=\"name\" name=\"name\" placeholder=\"Digite o nome do recurso\" type=\"text\"\" value=\"" + retField.result.info.name + "\">"); html += String.Format(infoTemplate, "Tipo de campo", "<select id=\"data_type\" name=\"data_type\" ><option value=\"string\" " + (retField.result.info.data_type == "string" ? "selected" : "") + ">Texto</option><option value=\"numeric\" " + (retField.result.info.data_type == "numeric" ? "selected" : "") + ">Número</option><option value=\"datetime\" " + (retField.result.info.data_type == "datetime" ? "selected" : "") + ">Data e Hora</option></select>"); html += String.Format(infoTemplate, "Público", "<input id=\"public\" name=\"public\" type=\"checkbox\" " + (retField.result.info.public_field? "checked":"") + "><span class=\"checkbox-label\">Permite visualização por todos os usuários</span>"); html += String.Format(infoTemplate, "Permite edição", "<input id=\"user\" name=\"user\" type=\"checkbox\" " + (retField.result.info.user_field ? "checked" : "") + "><span class=\"checkbox-label\">Permite que o usuário altere o valor</span>"); html += "<div class=\"clear-block\"></div></div>"; } else { html += "<h3>Informações gerais<div class=\"btn-box\"><div class=\"a-btn ico icon-change\" onclick=\"iamadmin.changeHash( 'edit/1' );\">Editar</div></div></h3>"; html += "<div class=\"no-tabs pb10\">"; html += String.Format(infoTemplate, "Nome", retField.result.info.name); html += String.Format(infoTemplate, "Tipo de campo", MessageResource.GetMessage(retField.result.info.data_type.ToLower())); html += String.Format(infoTemplate, "Público", (retField.result.info.public_field ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no"))); html += String.Format(infoTemplate, "Permite edição", (retField.result.info.user_field ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no"))); html += "<div class=\"clear-block\"></div></div>"; } if (hashData.GetValue("edit") == "1") { html += "<button type=\"submit\" id=\"resource-save\" class=\"button secondary floatleft\">Salvar</button> <a class=\"button link floatleft\" onclick=\"iamadmin.changeHash( 'edit/0' );\">Cancelar</a></form>"; } contentRet = new WebJsonResponse("#content-wrapper", html); contentRet.js = jsAdd; 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/field/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo campo</button></div>"; switch (filter) { case "add_user": break; default: /*if (retRole != null) * html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/roles/" + retRole.result.info.role_id + "/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Adicionar usuários</button></div>";*/ break; } } 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())); } }
private FilterRule GetFilterByForm(out WebJsonResponse contentRet) { contentRet = null; String name = Request.Form["filter_name"]; if (String.IsNullOrEmpty(name)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true); return(null); } String filters = Request.Form["filter_name"]; if (String.IsNullOrEmpty(name)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true); return(null); } //Verifica e trata as regras if (String.IsNullOrEmpty(Request.Form["filter_id"])) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("conditions_is_empty"), 3000, true); return(null); } String rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "field.list", parameters = new { page_size = Int32.MaxValue }, id = 1 }); //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); } finally { } List <FieldData> fieldList = new List <FieldData>(); FieldListResult flR = JSON.Deserialize <FieldListResult>(jData); if ((flR != null) && (flR.error == null) && (flR.result != null)) { fieldList = flR.result; } if (fieldList.Count == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); return(null); } FilterRule newItem = new FilterRule(name); String[] fIds = Request.Form["filter_id"].Split(",".ToCharArray()); foreach (String fid in fIds) { if (String.IsNullOrEmpty(Request.Form["filter_" + fid + "_group"])) { contentRet = new WebJsonResponse("", "Grupo não localizado na condição " + fid, 3000, true); break; } if (String.IsNullOrEmpty(Request.Form["filter_" + fid + "_field_id"])) { contentRet = new WebJsonResponse("", "ID do campo não localizado na condição " + fid, 3000, true); break; } String fGroup = Request.Form["filter_" + fid + "_group"].Split(",".ToCharArray())[0]; FieldData fieldData = null; try { Int64 tmp = Int64.Parse(Request.Form["filter_" + fid + "_field_id"].Split(",".ToCharArray())[0]); foreach (FieldData fd in fieldList) { if (fd.field_id == tmp) { fieldData = fd; } } if (fieldData == null) { throw new Exception(); } } catch { contentRet = new WebJsonResponse("", "ID do campo inválido na condição " + fid, 3000, true); break; } FilterSelector filterSelector = FilterSelector.AND; if (!String.IsNullOrEmpty(Request.Form["filter_" + fid + "_selector"])) { switch (Request.Form["filter_" + fid + "_selector"].Split(",".ToCharArray())[0].ToLower()) { case "or": filterSelector = FilterSelector.OR; break; default: filterSelector = FilterSelector.AND; break; } } FilterConditionType condition = FilterConditionType.Equal; switch (fieldData.data_type) { case "numeric": if (String.IsNullOrEmpty(Request.Form["filter_" + fid + "_condition_numeric"])) { contentRet = new WebJsonResponse("", "Condição de comparação não localizada na condição " + fid, 3000, true); break; } if (String.IsNullOrEmpty(Request.Form["filter_" + fid + "_text_numeric"])) { contentRet = new WebJsonResponse("", "Valor não localizado na condição " + fid, 3000, true); break; } Int64 nValue = 0; try { nValue = Int64.Parse(Request.Form["filter_" + fid + "_text_numeric"].Split(",".ToCharArray())[0]); } catch { contentRet = new WebJsonResponse("", "Valor inválido na condição " + fid, 3000, true); break; } String c1 = Request.Form["filter_" + fid + "_condition_numeric"].Split(",".ToCharArray())[0].ToLower(); foreach (FilterConditionType ft in IAM.Filters.FilterCondition.ConditionByDataType(DataType.Numeric)) { if (c1 == ft.ToString().ToLower()) { condition = ft; } } newItem.AddCondition(fGroup, FilterSelector.AND, fieldData.field_id, "", DataType.Numeric, nValue.ToString(), condition, filterSelector); break; case "datetime": if (String.IsNullOrEmpty(Request.Form["filter_" + fid + "_condition_datetime"])) { contentRet = new WebJsonResponse("", "Condição de comparação não localizada na condição " + fid, 3000, true); break; } if (String.IsNullOrEmpty(Request.Form["filter_" + fid + "_text_date"])) { contentRet = new WebJsonResponse("", "Valor de data não localizado na condição " + fid, 3000, true); break; } if (String.IsNullOrEmpty(Request.Form["filter_" + fid + "_text_time"])) { contentRet = new WebJsonResponse("", "Valor de hora não localizado na condição " + fid, 3000, true); break; } String dtValue = ""; try { if (Request.Form["filter_" + fid + "_text_date"].Split(",".ToCharArray())[0].ToLower() == "now") { dtValue = "now"; } else { DateTime tmp = DateTime.Parse(Request.Form["filter_" + fid + "_text_date"].Split(",".ToCharArray())[0] + " " + Request.Form["filter_" + fid + "_text_time"].Split(",".ToCharArray())[0]); dtValue = tmp.ToString("o"); } } catch { contentRet = new WebJsonResponse("", "Valor de data e hora inválidos na condição " + fid, 3000, true); break; } String c2 = Request.Form["filter_" + fid + "_condition_datetime"].Split(",".ToCharArray())[0].ToLower(); foreach (FilterConditionType ft in IAM.Filters.FilterCondition.ConditionByDataType(DataType.DateTime)) { if (c2 == ft.ToString().ToLower()) { condition = ft; } } newItem.AddCondition(fGroup, FilterSelector.AND, fieldData.field_id, "", DataType.DateTime, dtValue, condition, filterSelector); break; default: if (String.IsNullOrEmpty(Request.Form["filter_" + fid + "_condition_string"])) { contentRet = new WebJsonResponse("", "Condição de comparação não localizada na condição " + fid, 3000, true); break; } if (String.IsNullOrEmpty(Request.Form["filter_" + fid + "_text_string"])) { contentRet = new WebJsonResponse("", "Valor não localizado na condição " + fid, 3000, true); break; } String c3 = Request.Form["filter_" + fid + "_condition_string"].Split(",".ToCharArray())[0].ToLower(); foreach (FilterConditionType ft in IAM.Filters.FilterCondition.ConditionByDataType(DataType.Text)) { if (c3 == ft.ToString().ToLower()) { condition = ft; } } newItem.AddCondition(fGroup, FilterSelector.AND, fieldData.field_id, "", DataType.Text, Request.Form["filter_" + fid + "_text_string"].Split(",".ToCharArray())[0], condition, filterSelector); break; } } //Atualiza os seletores dos grupos caso haja mais de 1 grupo if (newItem.FilterGroups.Count > 1) { foreach (FilterGroup g in newItem.FilterGroups) { if (!String.IsNullOrEmpty(Request.Form["group_" + g.GroupId + "_selector"])) { switch (Request.Form["group_" + g.GroupId + "_selector"].Split(",".ToCharArray())[0].ToLower()) { case "and": g.Selector = FilterSelector.AND; break; default: g.Selector = FilterSelector.OR; break; } } } } return(newItem); }