/* * SBM - Control - Instance - Repository - Initialise. */ (function (win, doc, undef) { "use strict"; let ir = sbc.mdl.initRepository = { env: {} }; //-------------------------------------------------------------- /* Initialise Repository. Config: - id Repository - fnSuccess Callback */ sbc.fn.initialiseRepo = function (cfg) { //sbc.debug('initialiseRepo', cfg); let env = ir.env.init; env.cfg = cfg; let $frm = env.$frm.itemId; $frm.find('.RepositoryId').val(cfg.id) env.ajax.initQuery = env.ajax.initQuery || { url: sbc.url.base + 'Instance/Repository/Ajax/GetInitInfo', formSel: $frm, callbackFn: function (response) { ir.onInitQuery(env, response); } }; sbc.doAjaxRequest(env.ajax.initQuery, 50); } ir.onInitQuery = function (env, response) { sbc.debug('onInitQuery', response); if (!response.success) return; let $ctrls = env.$frm.init.find('.sbc-input,.sbc-textarea,.sbc-select').val(''); let repo = response.repository $ctrls.filter('.RepositoryId').val(repo.id); $ctrls.filter('.OwnerName').val(repo.ownerName); $ctrls.filter('.RepositoryContext').val(repo.context); let orgs = repo.organisations || []; if (orgs.length) { let org = orgs[0]; if (org.associationId && org.affiliateId) $ctrls.filter('.OrganisationExists').val(1); $ctrls.filter('.OrganisationAssociationId').val(org.associationId); $ctrls.filter('.OrganisationAffiliateId').val(org.affiliateId); $ctrls.filter('.OrganisationName').val(org.name); $ctrls.filter('.OrganisationWebsite').val(org.website); $ctrls.filter('.OrganisationCompanyNo').val(org.companyNo); $ctrls.filter('.OrganisationVatReg').val(org.vatReg); let usrs = org.users || []; if (usrs.length) { let usr = usrs[0]; if (usr.affiliateId && usr.securityItemId) $ctrls.filter('.UserExists').val(1); $ctrls.filter('.UserAffiliateId').val(usr.affiliateId); $ctrls.filter('.UserSecurityItemId').val(usr.securityItemId); $ctrls.filter('.UserFirstName').val(usr.firstName); $ctrls.filter('.UserLastName').val(usr.lastName); $ctrls.filter('.UserEmail').val(usr.email); $ctrls.filter('.UserCode').val(usr.code); } } sbc.openDialog(env.$dlg.init, 600, 640); } //-------------------------------------------------------------- ir.initRepo = function (env) { env.ajax.initRepo = env.ajax.initRepo || { url: sbc.url.base + 'Instance/Repository/Ajax/Initialise', formSel: env.$frm.init, callbackFn: function (response) { ir.onInitRepo(env, response); } }; sbc.doAjaxRequest(env.ajax.initRepo, 50); } ir.onInitRepo = function (env, response) { sbc.debug('onInitRepo', env, response); sbc.refreshControlValues(response.controlValues); if (!response.success) return; env.$dlg.init.dialog('close'); if (env.cfg.fnSuccess) env.cfg.fnSuccess(); delete env.cfg; } //-------------------------------------------------------------- $(function () { let env = ir.env.init = { data: {}, ajax: {}, $pnl: {}, $frm: {}, $ctrl: {}, $dlg: {} }; env.$pnl.init = $('.sbc-panel.RepositoryInit'); env.$frm.itemId = env.$pnl.init.find('.RepositoryIdForm'); let opt = sbc.dlgOpts(); opt.buttons[sbc.lbl.ok] = function () { ir.initRepo(env); }; opt.buttons[sbc.lbl.cancel] = function () { delete env.cfg; $(this).dialog('close'); }; env.$dlg.init = env.$pnl.init.find('.RepositoryInitDlg').dialog(opt); env.$frm.init = env.$dlg.init.find('.RepositoryInitForm'); env.$frm.init.on('input', '.sbc-input, .sbc-textarea', function () { sbc.clearControlError(this); }).on('change', '.sbc-select', function () { sbc.clearControlError(this); }); env.$frm.init.on('input', '.sbc-input.UserPassword', function () { env.$frm.init.find('.sbc-input.UserPasswordSet').val(1) }); }); //-------------------------------------------------------------- }(window, window.document)); /* The End */