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) { if (typeof(id)=='object') { var 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) { $("
", { class: "widget_panel_left" }).appendTo(".t_main #mainframe"); var divAccord=$("
",{ id: "accordion", class: "accordion" }).appendTo(".widget_panel_left"); $.each(panels,function (index,panel) { let px = $("

",{text: panel.title, append: panel.buttons }) .add($("
", { class: "widget lock c_contacts", id: "gendesc", text: langPack.core.iface.dataLoading})); px.appendTo(divAccord); }); $( "#accordion" ).accordion({ heightStyle: "content", activate: function( event, ui) { } }); } 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=$("
", { class: "widget_panel_right" }).appendTo(".t_main #mainframe"); createTabsPanel(panels,ref); } export function createTabsPanel(panels,ref) { if (ref===undefined) { ref=$(".t_main #mainframe"); } 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: $("