i am working on a mini contacts list and i am trying ot achieve a drag and drop effect. Right now i have a controller that brings me data from a DB and looks like this.
Index.controller('cIndex', function($scope, $http) {
$scope.init = function() {
$http.get('php/contacts.php').success(function(data) {
$scope.jsonContactsList = data;
$scope.jsonContactsDetail = [];
});
};
$scope.init();
$scope.listdetail = function(index) {
alert(index);
};
});
And this controller adds a list of contacts on the screen. I want to make that when i drag an item from the list and drop it outside the list, the item disapears from the list and appears as a detailed div about that specific contact.
Now i have 2 directives, 1 that makes the drag effect and 1 that makes the drop effect and they look like this.
Index.directive('contactListDrag', function() {
return {
restrict: 'A',
link: function(scope, elem, attr) {
var options = scope.$eval(attr.contactListDrag);
elem.draggable(options);
}
};
});
Index.directive('contactListDrop', function() {
return {
restrict: 'A',
link: function(scope, elem, attr) {
elem.droppable({accept: '.contact-list-item'});
elem.bind('drop', function(event, ui) {
var id = parseInt($(ui.draggable).attr('id'), 10);
$scope.listdetail(id);
});
}
};
});
Now inside the controller i have a function called listdetail, which i intend to make it change a line inside the jsonContactsList into jsonContactsDetail, but in order to do that, i need to call the listdetail function from the controller, inside the droppable contactListDrop directive.
Thank you in advance, Daniel!