From ab37be9aa99064848cf2549a32769e8833d19771 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 31 Jan 2010 16:40:27 -0500 Subject: [PATCH] category group editing --- classes/ComicPress.inc | 3 +- classes/ComicPressAdmin.inc | 39 +++++++++++++ .../partials/_category-grouping-editor.inc | 22 +++++++ classes/partials/options-admin.inc | 22 +++++++ css/cp-admin.css | 18 ++++++ js/CategoryGroups.js | 0 js/Storyline.js | 58 ++++++++++++++++++- 7 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 classes/partials/_category-grouping-editor.inc create mode 100644 js/CategoryGroups.js diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index ba7a956..2cede76 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -31,7 +31,8 @@ class ComicPress { ), 'helpers' => array(), 'storyline_order' => '', - 'enabled_backends' => null + 'enabled_backends' => null, + 'category_groupings' => array() ); var $backends = array(); diff --git a/classes/ComicPressAdmin.inc b/classes/ComicPressAdmin.inc index ba9c0d9..60c7788 100644 --- a/classes/ComicPressAdmin.inc +++ b/classes/ComicPressAdmin.inc @@ -224,6 +224,23 @@ class ComicPressAdmin { } } + function _render_admin_storyline_grouping_tree($node, $group_name, $category_ids) { + foreach ($node as $category_id => $children) { + $category = get_category($category_id); + echo '
  • '; + echo ''; + if (is_array($children)) { + echo ''; + } + echo '
  • '; + } + } + /** * Render the comic image ordering interface. */ @@ -394,6 +411,14 @@ class ComicPressAdmin { case 'enabled_backends': $this->comicpress->comicpress_options['enabled_backends'] = array_intersect(array_keys($info[$option]), $this->comicpress->get_valid_backends()); break; + case 'category_groupings': + $this->comicpress->comicpress_options['category_groupings'] = array(); + foreach ($info[$option] as $key => $settings) { + if (!empty($settings['name'])) { + $this->comicpress->comicpress_options['category_groupings'][$settings['name']] = isset($settings['category']) ? $settings['category'] : array(); + } + } + break; } } } @@ -452,6 +477,20 @@ class ComicPressAdmin { exit(0); } + + function handle_update_get_new_category_group_editor($info) { + $key = substr(md5(rand()), 0, 6); + $name = 'group'; + $category_ids = array(); + + $storyline = new ComicPressStoryline(); + $storyline->normalize(); + $storyline->read_from_options(); + + require_once('partials/_category-grouping-editor.inc'); + exit(0); + } + /** * Update the zoom slider info. * @param $info The browser input. diff --git a/classes/partials/_category-grouping-editor.inc b/classes/partials/_category-grouping-editor.inc new file mode 100644 index 0000000..c189877 --- /dev/null +++ b/classes/partials/_category-grouping-editor.inc @@ -0,0 +1,22 @@ +
    + X + + + + + + + + + +
    Group name: + +
    +
      + _render_admin_storyline_grouping_tree(reset($storyline->get_simple_storyline()), $key, $category_ids) ?> +
    +
    + +
    +
    +
    diff --git a/classes/partials/options-admin.inc b/classes/partials/options-admin.inc index b3324ad..37b2e19 100644 --- a/classes/partials/options-admin.inc +++ b/classes/partials/options-admin.inc @@ -7,6 +7,23 @@ +

    + +
    +
    + comicpress->comicpress_options['category_groupings'] as $name => $category_ids) { + $key = $name; + include('_category-grouping-editor.inc'); + } + ?> +
    + [+] Add a new category group + +
    + +
    +

    @@ -73,5 +90,10 @@ tab_holder.childElements().pop().addClassName('last'); show_tab(tab_holder.childElements().shift().id); + + Event.observe(document, 'dom:loaded', function() { + ComicPressAdmin.image_type_editor_nonce = ''; + ComicPressAdmin.category_group_editor_nonce = ''; + }); }()); diff --git a/css/cp-admin.css b/css/cp-admin.css index 42e55da..b164dd0 100644 --- a/css/cp-admin.css +++ b/css/cp-admin.css @@ -259,3 +259,21 @@ tr.highlighted td { border: solid black 1px; padding: 0 10px 10px; } + +.category-group-holder ul ul { + margin-left: 20px +} + +.category-group-holder { + border: solid #aaa 1px; + margin: 0 0 10px; + padding: 5px; +} + +.delete-category-group-holder { + float: right +} + +.category-group-holder .selected { + background-color: #99ccbb +} diff --git a/js/CategoryGroups.js b/js/CategoryGroups.js new file mode 100644 index 0000000..e69de29 diff --git a/js/Storyline.js b/js/Storyline.js index 0f3d855..91d16c2 100644 --- a/js/Storyline.js +++ b/js/Storyline.js @@ -1,5 +1,6 @@ var Storyline = {}; var ComicImageTypes = {}; +var CategoryGroupings = {}; (function() { Storyline.get_order = function() { @@ -76,7 +77,8 @@ var ComicImageTypes = {}; method: 'get', parameters: { 'cp[_nonce]': ComicPressAdmin.nonce, - 'cp[action]': 'get-new-image-type-editor' + 'cp[action]': 'get-new-image-type-editor', + 'cp[_action_nonce]': ComicPressAdmin.image_type_editor_nonce }, insertion: 'bottom', onComplete: function() { @@ -85,4 +87,58 @@ var ComicImageTypes = {}; }); }); }; + + CategoryGroupings.highlight_child_levels = function(e) { + $$('.category-group-holder input[type=checkbox]').each(function(cb) { + cb.disabled = false; + }); + + $$('.category-group-holder li').each(function(li) { + var all_cb = li.select('input[type=checkbox]'); + var cb = all_cb.shift(); + li.removeClassName('selected'); + if (cb && cb.checked) { + all_cb.each(function(ncb) { + ncb.disabled = true; + }); + li.addClassName('selected'); + } + }); + + $$('.category-group-holder').each(function(cgh) { + var all_off = true; + cgh.select('input[type=checkbox]').each(function(c) { + if (c.checked) { all_off = false; } + }); + cgh.select('.empty-group-warning').pop()[all_off ? 'show' : 'hide'](); + }); + } + + CategoryGroupings.setup_editors = function() { + $$('.category-group-holder input[type=checkbox], .category-group-holder label').each(function(cb) { + cb.stopObserving('click'); + cb.observe('click', CategoryGroupings.highlight_child_levels); + }); + } + + CategoryGroupings.setup = function() { + CategoryGroupings.setup_editors(); + CategoryGroupings.highlight_child_levels(); + + $('add-new-category-group').observe('click', function(e) { + Event.stop(e); + new Ajax.Updater('category-groups-holder', ComicPressAdmin.ajax_uri, { + method: 'get', + parameters: { + 'cp[_nonce]': ComicPressAdmin.nonce, + 'cp[action]': 'get-new-category-group-editor', + 'cp[_action_nonce]': ComicPressAdmin.category_group_editor_nonce + }, + onComplete: function() { + CategoryGroupings.setup_editors(); + }, + insertion: 'bottom' + }); + }); + } }())