Pārlūkot izejas kodu

First draft for drag and drop

We can change feed category by drag and drop! Need improvements...

See https://github.com/marienfressinaud/FreshRSS/issues/646
Marien Fressinaud 11 gadi atpakaļ
vecāks
revīzija
db4da3babc

+ 15 - 0
app/Controllers/feedController.php

@@ -378,6 +378,21 @@ 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,
+			);
+
+			$feedDAO->updateFeed($feed_id, $values);
+		}
+	}
+
 	public function deleteAction() {
 		if (Minz_Request::isPost()) {
 			$id = Minz_Request::param('id');

+ 2 - 0
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');

+ 2 - 2
app/views/subscription/index.phtml

@@ -113,14 +113,14 @@
 			</form>
 		</div>
 
-		<ul class="box-content">
+		<ul class="box-content" dropzone="move" 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(); ?>">
 				<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>

+ 55 - 0
p/scripts/category.js

@@ -0,0 +1,55 @@
+"use strict";
+
+
+function init_draggable() {
+	var feeds_draggable = '.box-content > .feed',
+	    box_dropzone = '.box-content';
+
+	$('.box').on('dragstart', feeds_draggable, function(e) {
+		e.originalEvent.dataTransfer.effectAllowed = 'move';
+		e.originalEvent.dataTransfer.setData('html', e.target.outerHTML);
+		e.originalEvent.dataTransfer.setData('feed-id', e.target.getAttribute('data-feed-id'));
+	});
+	$('.box').on('dragend', feeds_draggable, function(e) {
+		var parent = e.target.parentNode;
+		parent.removeChild(e.target);
+	});
+
+	$('.box').on('dragenter', box_dropzone, function(e) {
+		$(e.target).addClass('drag-hover');
+	});
+	$('.box').on('dragleave', box_dropzone, function(e) {
+		$(e.target).removeClass('drag-hover');
+	});
+	$('.box').on('dragover', box_dropzone, function(e) {
+		e.originalEvent.dataTransfer.dropEffect = "move";
+
+		return false;
+	});
+	$('.box').on('drop', box_dropzone, function(e) {
+		var feed_id = e.originalEvent.dataTransfer.getData('feed-id'),
+		    cat_id = e.target.parentNode.getAttribute('data-cat-id');
+
+		$.ajax({
+			type: 'POST',
+			url: './?c=feed&a=move',
+			data : {
+				f_id: feed_id,
+				c_id: cat_id
+			}
+		});
+
+		$(e.target).after(e.originalEvent.dataTransfer.getData('html'));
+		$(e.target).removeClass('drag-hover');
+		return false;
+	});
+}
+
+
+if (document.readyState && document.readyState !== 'loading') {
+	init_draggable();
+} else if (document.addEventListener) {
+	document.addEventListener('DOMContentLoaded', function () {
+		init_draggable();
+	}, false);
+}

+ 1 - 1
p/scripts/main.js

@@ -1247,7 +1247,7 @@ function init_slider_observers() {
 		return;
 	}
 
-	$('.open-slider').on('click', function() {
+	$('.post').on('click', '.open-slider', function() {
 		if (ajax_loading) {
 			return false;
 		}

+ 9 - 0
p/themes/Origine/origine.css

@@ -497,6 +497,15 @@ a.btn {
 	visibility: visible;
 }
 
+/*=== Draggable */
+.drag-hover {
+	background: #dfd;
+	transition: all linear 0.2s;
+}
+[draggable=true] {
+	cursor: grab;
+}
+
 /*=== STRUCTURE */
 /*===============*/
 /*=== Header */