import * as API from './api.js'; import * as UI from './ui.js'; import { langPack } from './langpack.js'; export function load() { UI.breadcrumbsUpdate(langPack.core.breadcrumbs.modTitle+" / "+langPack.core.breadcrumbs.users); UI.createTabsPanel({ users:{"title":langPack.core.iface.users.allTitle, preLoad: reloadUsers}, invites:{"title":langPack.core.iface.users.invitesTitle, preLoad: reloadInvites,buttons: UI.addButton({title: langPack.core.iface.users.inviteButtonTitle, icon: "fas fa-plus", onClick: btnInviteUser_Click})}, }) } function reloadUsers() { $("div.widget.users").empty(); API.exec("GET","core/user/list",{},function(json) { let tx = $("",{class: "datatable sel"}); $("",{}); $("",{append: row}).appendTo(tx); }); }) } function reloadInvites() { $("div.widget.invites").empty(); API.exec("GET","core/userInvitation/list",{},function(json) { let tx = $("
",{class: "idx", text: "#"}).appendTo(tx); $("",{class: "", text: langPack.core.iface.invCode}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.login}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.email}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.fullName}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.eMainConfirmedQTitle}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.active}).appendTo(tx); tx.appendTo("div.widget.users"); let i=0; $.each(json.data, function(idx, user) { i++; let row=$("
",{class: "idx", text: i}).appendTo(row); $("",{class: "", text: UI.formatInvCode(user.invCode)}).appendTo(row); $("",{class: "", text: user.login}).appendTo(row); $("",{class: "", text: user.eMail}).appendTo(row); $("",{class: "", text: user.fullName}).appendTo(row); $("",{class: "", text: user.eMailConfirmed}).appendTo(row); $("",{class: "", text: user.active}).appendTo(row); $("
",{class: "datatable sel"}); $("",{}).bind('contextmenu', uimContextMenuOpen).addClass("contextMenu").attr("invId",user.id).attr("xname",formatRegCode(user.regCode)); $("",{append: row}).appendTo(tx); }); }) } function uimContextMenuOpen(el) { let xName=$(el.target).closest("tr").attr("xname"); let xId=$(el.target).closest("tr").attr("invId"); UI.contextMenuOpen(el,[ {title: langPack.core.iface.delete, onClick: function() { var buttons={}; buttons[langPack.core.iface.dialodDelButton]=function() { $("#dialogInfo").dialog("close"); API.exec({ requestType: "DELETE", method: "core/userInvitation/"+xId, onSuccess: function(json) { reloadInvites(); }, errDict: langPack.core.iface.users.errors, }); }; buttons[langPack.core.iface.dialodCloseButton]=function() { $("#dialogInfo").dialog("close"); } UI.showInfoDialog(langPack.core.iface.users.delInvDialogTitle+" "+xName,langPack.core.iface.users.delInvDialogTitle,buttons); }}, ],xName); return false; } function formatRegCode(code) { if ((typeof(code) != 'string') ||code.length==0) { return langPack.core.iface.emptyInvCode; } else { return code.substr(0,4)+"-"+code.substr(4,4)+"-"+code.substr(8,4)+"-"+code.substr(12); } } function btnInviteUser_Click(ref) { var buttons={}; buttons[langPack.core.iface.dialodAddButton]=function() { let fdata=UI.collectForm("addgrp", true,false, false,true); if (fdata.validateErrCount==0) { API.exec({ errDict: langPack.core.iface.users.errors, requestType: "PUT", data: { eMail: fdata.email.val, expireStamp: isset(fdata.expiration.val)?UI.date2stamp(fdata.expiration.val):undefined, allowMultiUse: fdata.type.val, }, method: "core/userInvitation", onSuccess: function(json) { UI.closeDialog('addgrp'); reloadInvites(); } }); } }; buttons[langPack.core.iface.dialodCloseButton]=function() { UI.closeDialog('addgrp'); } UI.createDialog( UI.addFieldGroup([ UI.addField({item: "dag_email", title: langPack.core.iface.users.email, type: "input"}), UI.addField({item: "dag_type", title: langPack.core.iface.users.allowMultiUseTitle, type: "select",args: {"false":langPack.core.iface.no, "true": langPack.core.iface.yes}}), UI.addField({item: "dag_expiration", title: langPack.core.iface.users.invitationExpire, type: "datetime", args: {curr: UI.stamp2isodate(UI.getUnixTime(1209600))}}), ]), langPack.core.iface.dialodAddButton, buttons, 325,1,'addgrp'); UI.openDialog('addgrp') }
",{class: "idx", text: "#"}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.regCode}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.email}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.allowMultiUseQTitle}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.invitationExpire}).appendTo(tx); $("",{class: "", text: langPack.core.iface.users.inviteToGroupTitleQ}).appendTo(tx); $("",{class: "button", style: "text-align: center", append: $("",{class: "fas fa-ellipsis-h"})}).appendTo(tx); tx.appendTo("div.widget.invites"); let i=0; $.each(json.data, function(idx, user) { i++; let row=$("
",{class: "idx", text: i}).appendTo(row); $("",{class: "code", text: formatRegCode(user.regCode)}).appendTo(row); $("",{class: "", text: user.eMail}).appendTo(row); $("",{class: "", text: user.allowMultiUse?langPack.core.iface.yes:langPack.core.iface.no}).appendTo(row); $("",{class: "", text: UI.stamp2date(user.expireStamp,true)}).appendTo(row); $("",{class: "", text: user.joinGroupsId.length>0?langPack.core.iface.yes:langPack.core.iface.no}).appendTo(row); $("",{class: "button", style: "text-align: center", append: $("",{class: "fas fa-ellipsis-h"})}) .click(uimContextMenuOpen) .appendTo(row); $("