From 41925b37bb5892bb404bdf93a387afa601acfad4 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 28 Jul 2016 00:26:59 -0400 Subject: refactor admin dialogs --- src/guff/views/admin-page.cr | 16 +- src/guff/views/admin/dialogs/user-add.cr | 5 + src/guff/views/admin/dialogs/user-edit.cr | 3 + src/guff/views/admin/dialogs/user.cr | 11 + src/views/admin-page.ecr | 344 +----------------------------- src/views/admin/dialogs/user-add.ecr | 164 ++++++++++++++ src/views/admin/dialogs/user-edit.ecr | 178 ++++++++++++++++ 7 files changed, 370 insertions(+), 351 deletions(-) create mode 100644 src/guff/views/admin/dialogs/user-add.cr create mode 100644 src/guff/views/admin/dialogs/user-edit.cr create mode 100644 src/guff/views/admin/dialogs/user.cr create mode 100644 src/views/admin/dialogs/user-add.ecr create mode 100644 src/views/admin/dialogs/user-edit.ecr diff --git a/src/guff/views/admin-page.cr b/src/guff/views/admin-page.cr index b9dc6f2..c51ee1b 100644 --- a/src/guff/views/admin-page.cr +++ b/src/guff/views/admin-page.cr @@ -1,4 +1,5 @@ require "./html" +require "./admin/dialogs/*" class Guff::Views::AdminPageView < Guff::Views::HTMLView TITLE = "Guff Admin" @@ -149,14 +150,6 @@ class Guff::Views::AdminPageView < Guff::Views::HTMLView TEMPLATES[:new_post_button] end - private def role_options - @role_options ||= String.build do |io| - @context.models.role.get_roles.each do |row| - io << TEMPLATES[:option] % %w{role name}.map { |key| h(row[key]) } - end - end - end - private def state_buttons @state_buttons ||= String.build do |io| @context.models.state.get_states.each do |row| @@ -222,5 +215,12 @@ class Guff::Views::AdminPageView < Guff::Views::HTMLView { post_types: POST_TYPES}.to_json end + private def dialogs + String.build do |io| + io << Admin::Dialogs::UserAddDialog.new(@context) + io << Admin::Dialogs::UserEditDialog.new(@context) + end + end + ECR.def_to_s("src/views/admin-page.ecr") end diff --git a/src/guff/views/admin/dialogs/user-add.cr b/src/guff/views/admin/dialogs/user-add.cr new file mode 100644 index 0000000..e347225 --- /dev/null +++ b/src/guff/views/admin/dialogs/user-add.cr @@ -0,0 +1,5 @@ +require "./user" + +class Guff::Views::Admin::Dialogs::UserAddDialog < Guff::Views::Admin::Dialogs::UserDialog + ECR.def_to_s("src/views/admin/dialogs/user-add.ecr") +end diff --git a/src/guff/views/admin/dialogs/user-edit.cr b/src/guff/views/admin/dialogs/user-edit.cr new file mode 100644 index 0000000..e14211a --- /dev/null +++ b/src/guff/views/admin/dialogs/user-edit.cr @@ -0,0 +1,3 @@ +class Guff::Views::Admin::Dialogs::UserEditDialog < Guff::Views::Admin::Dialogs::UserDialog + ECR.def_to_s("src/views/admin/dialogs/user-edit.ecr") +end diff --git a/src/guff/views/admin/dialogs/user.cr b/src/guff/views/admin/dialogs/user.cr new file mode 100644 index 0000000..4bae8da --- /dev/null +++ b/src/guff/views/admin/dialogs/user.cr @@ -0,0 +1,11 @@ +class Guff::Views::Admin::Dialogs::UserDialog < Guff::Views::HTMLView + protected def role_options + tmpl = Guff::Views::AdminPageView::TEMPLATES[:option] + + @role_options ||= String.build do |io| + @context.models.role.get_roles.each do |row| + io << tmpl % %w{role name}.map { |key| h(row[key]) } + end + end + end +end diff --git a/src/views/admin-page.ecr b/src/views/admin-page.ecr index 00f2796..c06b5f0 100644 --- a/src/views/admin-page.ecr +++ b/src/views/admin-page.ecr @@ -557,349 +557,7 @@ - - - + <%= dialogs %>