From bb2a315df93c173db84d2d6fc0cf1b2bdbd931a7 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 30 Jul 2016 18:40:08 -0400 Subject: refactor site dialogs and add site editing --- src/guff/views/dialogs/admin/site-add.cr | 33 +--- src/guff/views/dialogs/admin/site-edit.cr | 14 ++ src/guff/views/dialogs/admin/site.cr | 37 +++++ src/guff/views/pages/admin.cr | 29 +++- src/views/dialogs/admin/site-add.ecr | 259 ----------------------------- src/views/dialogs/admin/site.ecr | 264 ++++++++++++++++++++++++++++++ 6 files changed, 351 insertions(+), 285 deletions(-) create mode 100644 src/guff/views/dialogs/admin/site-edit.cr delete mode 100644 src/views/dialogs/admin/site-add.ecr create mode 100644 src/views/dialogs/admin/site.ecr (limited to 'src') diff --git a/src/guff/views/dialogs/admin/site-add.cr b/src/guff/views/dialogs/admin/site-add.cr index c124457..50e051d 100644 --- a/src/guff/views/dialogs/admin/site-add.cr +++ b/src/guff/views/dialogs/admin/site-add.cr @@ -1,29 +1,14 @@ require "./site" class Guff::Views::Dialogs::Admin::SiteAdd < Guff::Views::Dialogs::Admin::Site - TABS = [{ - :id => "content", - :css => "active", - :icon => "fa-pencil", - :name => "Content", - :text => "View content tab.", - }, { - :id => "theme", - :css => "", - :icon => "fa-eye", - :name => "Theme", - :text => "View theme tab.", - }, { - :id => "other", - :css => "", - :icon => "fa-ellipsis-h", - :name => "Other", - :text => "View other tab.", - }] - - private def tabs - super("site-add", TABS) + def initialize(context : Context) + super( + context: context, + id: "site-add", + name: "New Site", + save_icon: "fa-plus-circle", + save_text: "Create site.", + save_name: "Create Site", + ) end - - ECR.def_to_s("src/views/dialogs/admin/site-add.ecr") end diff --git a/src/guff/views/dialogs/admin/site-edit.cr b/src/guff/views/dialogs/admin/site-edit.cr new file mode 100644 index 0000000..89dae69 --- /dev/null +++ b/src/guff/views/dialogs/admin/site-edit.cr @@ -0,0 +1,14 @@ +require "./site" + +class Guff::Views::Dialogs::Admin::SiteEdit < Guff::Views::Dialogs::Admin::Site + def initialize(context : Context) + super( + context: context, + id: "site-edit", + name: "Edit Site", + save_icon: "fa-save", + save_text: "Save changes.", + save_name: "Save Changes", + ) + end +end diff --git a/src/guff/views/dialogs/admin/site.cr b/src/guff/views/dialogs/admin/site.cr index c03cd0a..b916fd7 100644 --- a/src/guff/views/dialogs/admin/site.cr +++ b/src/guff/views/dialogs/admin/site.cr @@ -1,9 +1,44 @@ class Guff::Views::Dialogs::Admin::Site < Guff::Views::HTMLView + TABS = [{ + :id => "content", + :css => "active", + :icon => "fa-pencil", + :name => "Content", + :text => "View content tab.", + }, { + :id => "theme", + :css => "", + :icon => "fa-eye", + :name => "Theme", + :text => "View theme tab.", + }, { + :id => "other", + :css => "", + :icon => "fa-ellipsis-h", + :name => "Other", + :text => "View other tab.", + }] + OPTION_TEMPLATES = { y: "", n: "", } + def initialize( + context : Context, + @id : String, + @name : String, + @save_name : String, + @save_icon : String, + @save_text : String, + ) + super(context) + end + + protected def tabs + super(@id, TABS) + end + private def theme_options @context.models.theme.all.map { |row| { @@ -18,4 +53,6 @@ class Guff::Views::Dialogs::Admin::Site < Guff::Views::HTMLView OPTION_TEMPLATES[tmpl_id] % %i{id slug name}.map { |k| row[k] } }.join("") end + + ECR.def_to_s("src/views/dialogs/admin/site.ecr") end diff --git a/src/guff/views/pages/admin.cr b/src/guff/views/pages/admin.cr index 1c5f795..5ed95db 100644 --- a/src/guff/views/pages/admin.cr +++ b/src/guff/views/pages/admin.cr @@ -28,7 +28,9 @@ class Guff::Views::Pages::Admin < Guff::Views::HTMLView assets/js/admin/tabs/themes.js assets/js/admin/dialogs/user-add.js assets/js/admin/dialogs/user-edit.js + assets/js/admin/dialogs/site.js assets/js/admin/dialogs/site-add.js + assets/js/admin/dialogs/site-edit.js assets/js/admin/dialogs/post-edit.js assets/js/admin/dialogs/blog-edit.js assets/js/admin/dialogs/page-edit.js @@ -97,6 +99,7 @@ class Guff::Views::Pages::Admin < Guff::Views::HTMLView io << Dialogs::Admin::UserAdd.new(@context) io << Dialogs::Admin::UserEdit.new(@context) io << Dialogs::Admin::SiteAdd.new(@context) + io << Dialogs::Admin::SiteEdit.new(@context) io << Dialogs::Admin::BlogEdit.new(@context) io << Dialogs::Admin::PageEdit.new(@context) io << Dialogs::Admin::ProjectEdit.new(@context) @@ -104,12 +107,34 @@ class Guff::Views::Pages::Admin < Guff::Views::HTMLView end private def page_data + default_lang = "en-US" + default_theme_id = @context.models.theme.get_default_id + { post_types: POST_TYPES, sites: @context.models.site.get_sites, + + # TODO: refactor to defaults default_site_id: @context.models.site.get_default_id, - default_lang: "en-US", - default_theme_id: @context.models.theme.get_default_id, + default_lang: default_lang, + default_theme_id: default_theme_id, + + site_dialogs: { + paths: { + add: "site/add", + edit: "site/set", + }, + + fields: { + text: %w{name slug body lang theme_id}, + list: %w{domains styles scripts}, + + defaults: { + lang: default_lang, + theme_id: default_theme_id, + }, + }, + }, }.to_json end diff --git a/src/views/dialogs/admin/site-add.ecr b/src/views/dialogs/admin/site-add.ecr deleted file mode 100644 index 0f99364..0000000 --- a/src/views/dialogs/admin/site-add.ecr +++ /dev/null @@ -1,259 +0,0 @@ - diff --git a/src/views/dialogs/admin/site.ecr b/src/views/dialogs/admin/site.ecr new file mode 100644 index 0000000..fa5d7d7 --- /dev/null +++ b/src/views/dialogs/admin/site.ecr @@ -0,0 +1,264 @@ + -- cgit v1.2.3