|
4 | 4 | var config = ["$routeProvider", function ($routeProvider) { |
5 | 5 | $routeProvider |
6 | 6 | .when("/", { templateUrl: "app/dashboard/dashboardView.html" }) |
7 | | - |
| 7 | + |
8 | 8 | .when("/content/posts", { templateUrl: "app/content/posts/postView.html" }) |
9 | 9 | .when("/content/blogs", { templateUrl: "app/content/blogs/blogView.html" }) |
10 | 10 | .when("/content/comments", { templateUrl: "app/content/comments/commentView.html" }) |
|
81 | 81 | }; |
82 | 82 | }); |
83 | 83 |
|
| 84 | + // dragable |
| 85 | + app.factory('DragDropHandler', [function () { |
| 86 | + return { |
| 87 | + dragObject: undefined, |
| 88 | + addObject: function (object, objects, to) { |
| 89 | + objects.splice(to, 0, object); |
| 90 | + }, |
| 91 | + moveObject: function (objects, from, to) { |
| 92 | + objects.splice(to, 0, objects.splice(from, 1)[0]); |
| 93 | + } |
| 94 | + }; |
| 95 | + }]); |
| 96 | + |
| 97 | + app.directive('draggable', ['DragDropHandler', function (DragDropHandler) { |
| 98 | + return { |
| 99 | + scope: { |
| 100 | + draggable: '=' |
| 101 | + }, |
| 102 | + link: function (scope, element, attrs) { |
| 103 | + element.draggable({ |
| 104 | + connectToSortable: attrs.draggableTarget, |
| 105 | + helper: "clone", |
| 106 | + start: function () { |
| 107 | + DragDropHandler.dragObject = scope.draggable; |
| 108 | + }, |
| 109 | + stop: function () { |
| 110 | + DragDropHandler.dragObject = undefined; |
| 111 | + } |
| 112 | + }); |
| 113 | + |
| 114 | + element.disableSelection(); |
| 115 | + } |
| 116 | + }; |
| 117 | + }]); |
| 118 | + |
| 119 | + app.directive('droppable', ['DragDropHandler', function (DragDropHandler) { |
| 120 | + return { |
| 121 | + scope: { |
| 122 | + droppable: '=', |
| 123 | + ngMove: '&', |
| 124 | + ngCreate: '&' |
| 125 | + }, |
| 126 | + link: function (scope, element, attrs) { |
| 127 | + element.sortable({ |
| 128 | + connectWith: ['.draggable', '.sortable'], |
| 129 | + }); |
| 130 | + element.disableSelection(); |
| 131 | + var list = element.attr('id'); |
| 132 | + element.on("sortupdate", function (event, ui) { |
| 133 | + |
| 134 | + var from = angular.element(ui.item).scope().$index; |
| 135 | + var to = element.children().index(ui.item); |
| 136 | + |
| 137 | + if (to >= 0) { |
| 138 | + //item is moved to this list |
| 139 | + scope.$apply(function () { |
| 140 | + if (from >= 0) { |
| 141 | + //item is coming from a sortable |
| 142 | + |
| 143 | + if (!ui.sender) { |
| 144 | + //item is coming from this sortable |
| 145 | + DragDropHandler.moveObject(scope.droppable, from, to); |
| 146 | + |
| 147 | + } else { |
| 148 | + //item is coming from another sortable |
| 149 | + scope.ngMove({ |
| 150 | + from: from, |
| 151 | + to: to, |
| 152 | + fromList: ui.sender.attr('id'), |
| 153 | + toList: list |
| 154 | + }); |
| 155 | + ui.item.remove(); |
| 156 | + } |
| 157 | + } else { |
| 158 | + //item is coming from a draggable |
| 159 | + scope.ngCreate({ |
| 160 | + object: DragDropHandler.dragObject, |
| 161 | + to: to, |
| 162 | + list: list |
| 163 | + }); |
| 164 | + |
| 165 | + ui.item.remove(); |
| 166 | + } |
| 167 | + }); |
| 168 | + } |
| 169 | + }); |
| 170 | + |
| 171 | + } |
| 172 | + }; |
| 173 | + }]); |
| 174 | + // end dragable |
| 175 | + |
84 | 176 | var run = ["$rootScope", "$log", function ($rootScope, $log) { |
85 | 177 |
|
86 | 178 | $rootScope.lbl = BlogAdmin.i18n; |
|
0 commit comments