import { langPack } from './langpack.js'; import * as API from './api.js'; import { smartClick } from './main.js'; var codes={ "400":"Bad request", "401":"Unauthorized", "403":"Forbidden", "404":"Not found", "405":"Method Not Allowed", "500":"Internal server error", "501":"Not Implemented", }; export function showError(code, message) { if (message==undefined) { message=codes[code]} if (message==undefined) { message="Internal server error"} $("
", { class: "error blanker bggray"}).appendTo("body"); $("
", { class: "error error_banner",html: "ERROR "+code+"
"+message}).appendTo("body"); } export function hideError() { $("body div.error").remove(); } export function click (ref) { return smartClick(ref); } export function addButton(id, icon, title, color, onClick, cssClass, style) { var opts; if (typeof(id)=='object') { opts=id; id=opts.id; icon=opts.icon; title=opts.title; color=opts.color; onClick=opts.onClick; cssClass=opts.cssClass; style=opts.style; } else { opts={}; } if (cssClass===undefined) { cssClass = "short super";} let btn=$("
", { class: "button "+cssClass+" "+color, id: id, append: $("", {class: icon }), style: style, }).attr("title", title); $.each(opts.attr, function(key,val) { btn.attr(key,val); }); if (style!==undefined) { btn.style=style; } if (typeof(onClick) == 'function') { btn.click(function(ref) { onClick(ref); return false;}); } return btn; } export function parceURL() { let pattern = /([^:]{1,}):\/\/([^\/#?]{1,})(\/([^\/#?]{1,})){0,1}(\/([^\/#?]{1,})){0,1}(\/([^\/#?]{1,})){0,1}/i; let pattern2 = /([#](.*)){0,1}$/i; let px = document.location.href.match(pattern); let px2=document.location.href.match(pattern2); let rv={ proto: px[1], host: px[2], module: px[4], function: px[6], id: px[8], marker: px2[2] }; if (rv.id=='') { rv.id=undefined; } let args=document.location.href.split('?')[1]; let rva=[]; if (typeof(args)=='string') { args=args.split('&'); } else { args=[]; } $.each(args,function(key,val) { rva[val.split("=")[0]]=val.split("=")[1]; }); rv.args=rva; return rv; } export function empty() { $(".t_main #mainframe").empty(); } /* panels is array panel_desc= [{ id, title, buttons [ addButton() (.....) ] }] */ export function createLeftPanel(panels, config) { if (config==undefined) { config={};} let ref; if (config.ref) { ref=config.ref; } else { if (!ref) { ref =$(".t_main #mainframe div.widget_panel_left"); } } if (ref.length==0) { ref=$("
", { class: "widget_panel_left" }).appendTo(".t_main #mainframe"); } else { ref.empty(); } var divAccord=$("
",{ id: "accordion", class: "accordion" }).appendTo(ref); $.each(panels,function (_index,panel) { let xpdiv=$("
", { class: "widget lock c_contacts", id: panel.id, text: langPack.core.iface.dataLoading, style: panel.disabled?"display: none":""}); if (panel.attrs) { $.each(panel.attrs, function (key, val) { xpdiv.attr(key,val); }); } let px = $("

",{text: panel.title, id: panel.id+"_title", append: panel.buttons, style: panel.disabled?"display: none":"" }) .add(xpdiv); px.appendTo(divAccord); }); let accConfig={ heightStyle: "content", }; if (typeof(config.beforeActivate)=="function") { accConfig.beforeActivate=config.beforeActivate; } if (typeof(config.activate)=="function") { accConfig.activate=config.activate; } if (typeof(config.create)=="function") { accConfig.create=config.create; } $("#accordion" ).accordion(accConfig); } function panelBeforeActivate(panel, callback) { $("#tab_buttons .button_block").hide(); let fx=callback[panel.prop("id").replace(/^[^\-\_]*[\-\_]/,"")]; if (typeof(fx) == 'function') { $("div.widget."+panel.prop("id").replace(/^[^\-\_]*[\-\_]/,"")).empty();; fx(); } } function panelActivate(panel, callback) { $(panel.prop("id").replace(/^[^\-\_]*[\-\_]/,"#buttons_")).show(); $(panel.prop("id").replace(/^[^\-\_]*[\-\_]/,"#buttons_")+" .x_status .hideme").hide(); } export function createRightPanel(panels) { let ref=($(".t_main #mainframe div.widget_panel_right")); if (ref.length==0) { ref=$("
", { class: "widget_panel_right" }).appendTo(".t_main #mainframe"); } createTabsPanel(panels,ref); } export function tabPanelRenameTab(tabId, text) { $("#a-tab-"+tabId).text(text); } export function tabPanelHideTab(tabId) { $( "#item_tabs").tabs("disable","#tab-"+tabId); } export function tabPanelShowTab(tabId) { $( "#item_tabs").tabs("enable","#tab-"+tabId); } export function tabPanelActivateTab(tabId) { $("#item_tabs").tabs({active: Number($("#a-tab-"+tabId).attr("idx"))}); } export function createTabsPanel(panels,ref) { if (ref===undefined) { ref=$(".t_main #mainframe"); } else { ref.empty(); } var callback={}; let divTabs=$("
",{ id: "item_tabs", class: "ui-tabs-main-div", append: $("
",{ class: "ui-tabs-title-line", append: $("
",{ style: "display: inline-block; float: left;", append: $("