diff options
| author | 2014-10-02 19:49:49 +0200 | |
|---|---|---|
| committer | 2014-10-02 19:49:49 +0200 | |
| commit | 43c1183c93d149f74dbb02887cfb0ca86c71fed8 (patch) | |
| tree | 530e926a456b07a869a0ea7a15616623c67b5d95 | |
| parent | 9b2ad32e98e4720d5ee422fccd3069f086ee8563 (diff) | |
| parent | ce43b1761b810c89e5e8660e8ae2638e97ca6339 (diff) | |
Merge branch '646-new-cat-system' into dev
| -rwxr-xr-x | app/Controllers/feedController.php | 20 | ||||
| -rw-r--r-- | app/Controllers/subscriptionController.php | 2 | ||||
| -rw-r--r-- | app/views/helpers/javascript_vars.phtml | 1 | ||||
| -rw-r--r-- | app/views/subscription/index.phtml | 11 | ||||
| -rw-r--r-- | p/scripts/category.js | 118 | ||||
| -rw-r--r-- | p/scripts/main.js | 2 | ||||
| -rw-r--r-- | p/themes/Origine/origine.css | 1 | ||||
| -rw-r--r-- | p/themes/base-theme/template.css | 12 |
8 files changed, 162 insertions, 5 deletions
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index e4859b110..b2b53185e 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -378,6 +378,26 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } + public function moveAction() { + if (Minz_Request::isPost()) { + $feed_id = Minz_Request::param('f_id'); + $cat_id = Minz_Request::param('c_id'); + + $feedDAO = FreshRSS_Factory::createFeedDao(); + + $values = array( + 'category' => $cat_id, + ); + + if (!$feedDAO->updateFeed($feed_id, $values)) { + Minz_Error::error( + 404, + array('error' => array(_t('error_occurred'))) + ); + } + } + } + public function deleteAction() { if (Minz_Request::isPost()) { $id = Minz_Request::param('id'); diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php index aabae7b8f..7cc8179a0 100644 --- a/app/Controllers/subscriptionController.php +++ b/app/Controllers/subscriptionController.php @@ -30,6 +30,8 @@ class FreshRSS_subscription_Controller extends Minz_ActionController { * It displays categories and associated feeds. */ public function indexAction() { + Minz_View::appendScript(Minz_Url::display('/scripts/category.js?' . + @filemtime(PUBLIC_PATH . '/scripts/category.js'))); Minz_View::prependTitle(_t('subscription_management') . ' · '); $id = Minz_Request::param('id'); diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index 1139eb446..71798369d 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -54,6 +54,7 @@ echo 'authType="', $authType, '",', echo 'str_confirmation_default="', Minz_Translate::t('confirm_action'), '"', ",\n"; echo 'str_notif_title_articles="', Minz_Translate::t('notif_title_new_articles'), '"', ",\n"; echo 'str_notif_body_articles="', Minz_Translate::t('notif_body_new_articles'), '"', ",\n"; +echo 'str_category_empty="', Minz_Translate::t('category_empty'), '"', ",\n"; echo 'html5_notif_timeout=', $this->conf->html5_notif_timeout,",\n"; diff --git a/app/views/subscription/index.phtml b/app/views/subscription/index.phtml index 577ddd972..2c56f79ed 100644 --- a/app/views/subscription/index.phtml +++ b/app/views/subscription/index.phtml @@ -1,6 +1,6 @@ <?php $this->partial('aside_subscription'); ?> -<div class="post"> +<div class="post drop-section"> <a href="<?php echo _url('index', 'index'); ?>"><?php echo _t('back_to_rss_feeds'); ?></a> <h2><?php echo _t('subscription_management'); ?></h2> @@ -113,21 +113,24 @@ </form> </div> - <ul class="box-content"> + <ul class="box-content" data-cat-id="<?php echo $cat->id(); ?>"> <?php if (!empty($feeds)) { ?> <?php foreach ($feeds as $feed) { $error = $feed->inError() ? ' error' : ''; $empty = $feed->nbEntries() == 0 ? ' empty' : ''; ?> - <li class="item<?php echo $error, $empty; ?>"> + <li class="item feed<?php echo $error, $empty; ?>" + draggable="true" + data-feed-id="<?php echo $feed->id(); ?>" + dropzone="move"> <a class="configure open-slider" href="<?php echo _url('subscription', 'feed', 'id', $feed->id()); ?>"><?php echo _i('configure'); ?></a> <img class="favicon" src="<?php echo $feed->favicon(); ?>" alt="✇" /> <?php echo $feed->name(); ?> </li> <?php } } else { ?> - <li class="item"><?php echo _t('category_empty'); ?></li> + <li class="item disabled" dropzone="move"><?php echo _t('category_empty'); ?></li> <?php } ?> </ul> </div> diff --git a/p/scripts/category.js b/p/scripts/category.js new file mode 100644 index 000000000..dc5df67e4 --- /dev/null +++ b/p/scripts/category.js @@ -0,0 +1,118 @@ +"use strict"; + +var loading = false, + dnd_successful = false; + +function dragend_process(t) { + t.style.display = 'none'; + + if (loading) { + window.setTimeout(function() { + dragend_process(t); + }, 50); + } + + if (!dnd_successful) { + t.style.display = 'block'; + t.style.opacity = 1.0; + } else { + var parent = $(t.parentNode); + $(t).remove(); + + if (parent.children().length <= 0) { + parent.append('<li class="item disabled" dropzone="move">' + str_category_empty + '</li>'); + } + } +} + +function init_draggable() { + if (!(window.$ && window.url_freshrss)) { + if (window.console) { + console.log('FreshRSS waiting for JS…'); + } + window.setTimeout(init_draggable, 50); + return; + } + + $.event.props.push('dataTransfer'); + + var draggable = '[draggable="true"]', + dropzone = '[dropzone="move"]'; + + $('.drop-section').on('dragstart', draggable, function(e) { + e.dataTransfer.effectAllowed = 'move'; + e.dataTransfer.setData('text/html', e.target.outerHTML); + e.dataTransfer.setData('text', e.target.getAttribute('data-feed-id')); + e.target.style.opacity = 0.3; + + dnd_successful = false; + }); + $('.drop-section').on('dragend', draggable, function(e) { + dragend_process(e.target); + }); + + $('.drop-section').on('dragenter', dropzone, function(e) { + $(this).addClass('drag-hover'); + + e.preventDefault(); + }); + $('.drop-section').on('dragleave', dropzone, function(e) { + var pos_this = $(this).position(), + scroll_top = $(document).scrollTop(), + top = pos_this.top, + left = pos_this.left, + right = left + $(this).width(), + bottom = top + $(this).height(), + mouse_x = e.originalEvent.screenX, + mouse_y = e.originalEvent.clientY + scroll_top; + + if (left <= mouse_x && mouse_x <= right && + top <= mouse_y && mouse_y <= bottom) { + // HACK because dragleave is triggered when hovering children! + return; + } + $(this).removeClass('drag-hover'); + }); + $('.drop-section').on('dragover', dropzone, function(e) { + e.dataTransfer.dropEffect = "move"; + + e.preventDefault(); + return false; + }); + $('.drop-section').on('drop', dropzone, function(e) { + var feed_id = e.dataTransfer.getData('text'), + cat_id = e.target.parentNode.getAttribute('data-cat-id'); + + loading = true; + + $.ajax({ + type: 'POST', + url: './?c=feed&a=move', + data : { + f_id: feed_id, + c_id: cat_id + } + }).success(function() { + $(e.target).after(e.dataTransfer.getData('text/html')); + if ($(e.target).hasClass('disabled')) { + $(e.target).remove(); + } + dnd_successful = true; + }).complete(function() { + loading = false; + }); + + $(this).removeClass('drag-hover'); + + e.preventDefault(); + }); +} + + +if (document.readyState && document.readyState !== 'loading') { + init_draggable(); +} else if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', function () { + init_draggable(); + }, false); +} diff --git a/p/scripts/main.js b/p/scripts/main.js index c9e8dd299..37281a907 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1240,7 +1240,7 @@ function init_slider_observers() { return; } - $('.open-slider').on('click', function() { + $('.post').on('click', '.open-slider', function() { if (ajax_loading) { return false; } diff --git a/p/themes/Origine/origine.css b/p/themes/Origine/origine.css index e3ae85075..b25deab0c 100644 --- a/p/themes/Origine/origine.css +++ b/p/themes/Origine/origine.css @@ -481,6 +481,7 @@ a.btn { border-radius: 5px 5px 0 0; } .box .box-content { + min-height: 2.5em; max-height: 260px; } diff --git a/p/themes/base-theme/template.css b/p/themes/base-theme/template.css index e6c832ee4..06874c9fe 100644 --- a/p/themes/base-theme/template.css +++ b/p/themes/base-theme/template.css @@ -304,6 +304,10 @@ a.btn { .box .box-content .item { display: block; } +.box .box-content .item.disabled { + text-align: center; + font-style: italic; +} .box .box-content-centered { padding: 30px 5px; @@ -313,6 +317,14 @@ a.btn { margin: 20px 0 0; } +/*=== Draggable */ +.drag-hover { + margin: 0 0 5px; + border-bottom: 2px solid #ccc; +} +[draggable=true] { + cursor: grab; +} /*=== STRUCTURE */ /*===============*/ |
