Skip to content

Commit e217edd

Browse files
author
Andrei Kraykov
committed
dropped event and drag from desktop event handlers
1 parent d37fa57 commit e217edd

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/js/controllers/main.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,78 @@
339339
});
340340
};
341341

342+
$scope.droppedFromDesktop = function(dragEl, dropEl, dragFiles) { // function referenced by the drop target
343+
//this is application logic, for the demo we just want to color the grid squares
344+
//the directive provides a native dom object, wrap with jqlite
345+
var drop = angular.element(dropEl);
346+
var drag = angular.element(dragEl);
347+
348+
//clear the previously applied color, if it exists
349+
var bgClass = drop.attr('data-color');
350+
if (bgClass) {
351+
drop.removeClass(bgClass);
352+
}
353+
354+
//add the dragged color
355+
bgClass = drag.attr("data-color");
356+
drop.addClass(bgClass);
357+
drop.attr('data-color', bgClass);
358+
359+
//if element has been dragged from the grid, clear dragged color
360+
if (drag.attr("x-lvl-drop-zone")) {
361+
drag.removeClass(bgClass);
362+
}
363+
364+
$scope.addForUpload([].slice.call(dragFiles));
365+
}
366+
$scope.dropped = function(dragEl, dropEl, item) { // function referenced by the drop target
367+
//this is application logic, for the demo we just want to color the grid squares
368+
//the directive provides a native dom object, wrap with jqlite
369+
var drop = angular.element(dropEl);
370+
var drag = angular.element(dragEl);
371+
372+
//clear the previously applied color, if it exists
373+
var bgClass = drop.attr('data-color');
374+
if (bgClass) {
375+
drop.removeClass(bgClass);
376+
}
377+
378+
//add the dragged color
379+
bgClass = drag.attr("data-color");
380+
drop.addClass(bgClass);
381+
drop.attr('data-color', bgClass);
382+
383+
//if element has been dragged from the grid, clear dragged color
384+
if (drag.attr("x-lvl-drop-target")) {
385+
drag.removeClass(bgClass);
386+
}
387+
388+
//moving files and directories
389+
if($scope.temps.indexOf(item) !== -1){
390+
//can't drop here
391+
return;
392+
} else {
393+
//set destination path
394+
for(var i =0; i< $scope.temps.length; i ++){
395+
$scope.temps[i].tempModel.path = item.model.fullPath().split('/');
396+
}
397+
//move all files
398+
Promise.all($scope.temps.map(function(drag, i){
399+
drag.rename().then(function () {
400+
var deferred = $q.defer();
401+
FileNavigator.clearTree(drag);
402+
return deferred.promise;
403+
}, function(error) {
404+
$scope.temp.error = error;
405+
});
406+
})).then(function(data){
407+
FileNavigator.refresh();
408+
},function(err){
409+
FileNavigator.refresh();
410+
});
411+
}
412+
}
413+
342414
var validateSamePath = function(item) {
343415
var selectedPath = $rootScope.selectedModalPath.join('');
344416
var selectedItemsPath = item && item.model.path.join('');

0 commit comments

Comments
 (0)