From 3ab800d49f555cb1900eb15f693b81e3cf8cce1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 12 Oct 2022 12:40:35 -0400 Subject: [PATCH] refactor: move embedded group create modal and fix its styling --- public/src/admin/manage/groups.js | 89 +++++++++++-------- src/views/admin/manage/groups.tpl | 45 ---------- .../admin/partials/create_group_modal.tpl | 39 ++++++++ 3 files changed, 89 insertions(+), 84 deletions(-) create mode 100644 src/views/admin/partials/create_group_modal.tpl diff --git a/public/src/admin/manage/groups.js b/public/src/admin/manage/groups.js index 28b00a00da..bd31f38dba 100644 --- a/public/src/admin/manage/groups.js +++ b/public/src/admin/manage/groups.js @@ -10,48 +10,11 @@ define('admin/manage/groups', [ const Groups = {}; Groups.init = function () { - const createModal = $('#create-modal'); - const createGroupName = $('#create-group-name'); - const createModalGo = $('#create-modal-go'); - const createModalError = $('#create-modal-error'); + + handleCreate(); handleSearch(); - createModal.on('keypress', function (e) { - if (e.keyCode === 13) { - createModalGo.click(); - } - }); - - $('#create').on('click', function () { - createModal.modal('show'); - setTimeout(function () { - createGroupName.focus(); - }, 250); - }); - - createModalGo.on('click', function () { - const submitObj = { - name: createGroupName.val(), - description: $('#create-group-desc').val(), - private: $('#create-group-private').is(':checked') ? 1 : 0, - hidden: $('#create-group-hidden').is(':checked') ? 1 : 0, - }; - - api.post('/groups', submitObj).then((response) => { - createModalError.addClass('hide'); - createGroupName.val(''); - createModal.on('hidden.bs.modal', function () { - ajaxify.go('admin/manage/groups/' + response.name); - }); - createModal.modal('hide'); - }).catch((err) => { - if (!utils.hasLanguageKey(err.status.message)) { - err.status.message = '[[admin/manage/groups:alerts.create-failure]]'; - } - createModalError.translateHtml(err.status.message).removeClass('hide'); - }); - }); $('.groups-list').on('click', '[data-action]', function () { const el = $(this); @@ -84,6 +47,54 @@ define('admin/manage/groups', [ }); } + function handleCreate() { + $('#create').on('click', function () { + app.parseAndTranslate('admin/partials/create_group_modal', {}).then((html) => { + html.modal('show'); + + html.on('shown.bs.modal', function () { + const createModal = $('#create-modal'); + const createGroupName = $('#create-group-name'); + const createModalGo = $('#create-modal-go'); + const createModalError = $('#create-modal-error'); + + createGroupName.trigger('focus'); + createModal.on('keypress', function (e) { + if (e.key === 'Enter') { + createModalGo.trigger('click'); + } + }); + html.on('hidden.bs.modal', function () { + html.modal('hide'); + createModal.remove(); + }); + createModalGo.on('click', function () { + const submitObj = { + name: createGroupName.val(), + description: $('#create-group-desc').val(), + private: $('#create-group-private').is(':checked') ? 1 : 0, + hidden: $('#create-group-hidden').is(':checked') ? 1 : 0, + }; + + api.post('/groups', submitObj).then((response) => { + createModalError.addClass('hide'); + createGroupName.val(''); + createModal.on('hidden.bs.modal', function () { + ajaxify.go('admin/manage/groups/' + response.name); + }); + createModal.modal('hide'); + }).catch((err) => { + if (!utils.hasLanguageKey(err.status.message)) { + err.status.message = '[[admin/manage/groups:alerts.create-failure]]'; + } + createModalError.translateHtml(err.status.message).removeClass('hide'); + }); + }); + }); + }); + }); + } + function handleSearch() { const queryEl = $('#group-search'); diff --git a/src/views/admin/manage/groups.tpl b/src/views/admin/manage/groups.tpl index fc43cf762d..bb744136a1 100644 --- a/src/views/admin/manage/groups.tpl +++ b/src/views/admin/manage/groups.tpl @@ -60,51 +60,6 @@ - - + + + + + + \ No newline at end of file