diff --git a/app/javascript/vue/forms/table.vue b/app/javascript/vue/forms/table.vue index 89da5eaa7..feb28d1f0 100644 --- a/app/javascript/vue/forms/table.vue +++ b/app/javascript/vue/forms/table.vue @@ -5,9 +5,14 @@ :dataUrl="dataSource" :reloadingTable="reloadingTable" :toolbarActions="toolbarActions" + :activePageUrl="activePageUrl" + :archivedPageUrl="archivedPageUrl" + :currentViewMode="currentViewMode" :actionsUrl="actionsUrl" @tableReloaded="reloadingTable = false" @create="createForm" + @archive="archive" + @restore="restore" @access="access" /> @@ -52,7 +57,10 @@ export default { userRolesUrl: { type: String, required: true - } + }, + activePageUrl: { type: String }, + archivedPageUrl: { type: String }, + currentViewMode: { type: String, required: true } }, data() { return { @@ -129,6 +137,22 @@ export default { object: rows[0], roles_path: this.userRolesUrl }; + }, + archive(event) { + axios.post(event.path).then((response) => { + this.reloadingTable = true; + HelperModule.flashAlertMsg(response.data.message, 'success'); + }).catch((error) => { + HelperModule.flashAlertMsg(error.response.data.error, 'danger'); + }); + }, + restore(event) { + axios.post(event.path).then((response) => { + this.reloadingTable = true; + HelperModule.flashAlertMsg(response.data.message, 'success'); + }).catch((error) => { + HelperModule.flashAlertMsg(error.response.data.error, 'danger'); + }); } } }; diff --git a/app/services/lists/forms_service.rb b/app/services/lists/forms_service.rb index c6460b5e2..0c7b61cd0 100644 --- a/app/services/lists/forms_service.rb +++ b/app/services/lists/forms_service.rb @@ -9,6 +9,11 @@ module Lists def fetch_records @records = Form.where(team: @team).readable_by_user(@user) + + view_mode = @params[:view_mode] || 'active' + + @records = @records.archived if view_mode == 'archived' + @records = @records.active if view_mode == 'active' end def filter_records; end diff --git a/app/services/toolbars/forms_service.rb b/app/services/toolbars/forms_service.rb index c62817af8..4abf3919e 100644 --- a/app/services/toolbars/forms_service.rb +++ b/app/services/toolbars/forms_service.rb @@ -18,7 +18,9 @@ module Toolbars return [] if @forms.none? [ - access_action + access_action, + archive_action, + restore_action ].compact end @@ -34,5 +36,29 @@ module Toolbars type: :emit } end + + def archive_action + return unless @forms.all? { |form| can_archive_form?(form) } + + { + name: 'archive', + label: I18n.t('forms.index.toolbar.archive'), + icon: 'sn-icon sn-icon-archive', + path: archive_forms_path(form_ids: @forms.pluck(:id)), + type: :emit + } + end + + def restore_action + return unless @forms.all? { |form| can_restore_form?(form) } + + { + name: 'restore', + label: I18n.t('forms.index.toolbar.restore'), + icon: 'sn-icon sn-icon-restore', + path: restore_forms_path(form_ids: @forms.pluck(:id)), + type: :emit + } + end end end diff --git a/app/views/forms/index.html.erb b/app/views/forms/index.html.erb index 17eee3383..003a86af1 100644 --- a/app/views/forms/index.html.erb +++ b/app/views/forms/index.html.erb @@ -13,6 +13,9 @@ data-source="<%= forms_path(format: :json) %>" create-url="<%= forms_path %>" user-roles-url="<%= user_roles_forms_path %>" + active-page-url="<%= forms_path(view_mode: :active) %>" + archived-page-url="<%= forms_path(view_mode: :archived) %>" + current-view-mode="<%= params[:view_mode] || :active %>" /> diff --git a/config/locales/en.yml b/config/locales/en.yml index e6aa4826b..f573fcde5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1075,6 +1075,8 @@ en: toolbar: new: 'New form' access: 'Access' + archive: 'Archive' + restore: 'Restore' table: name: 'Form name' code: 'ID'