{"action":"created","issue":{"url":"https://api.github.com/repos/marceljuenemann/angular-drag-and-drop-lists/issues/52","labels_url":"https://api.github.com/repos/marceljuenemann/angular-drag-and-drop-lists/issues/52/labels{/name}","comments_url":"https://api.github.com/repos/marceljuenemann/angular-drag-and-drop-lists/issues/52/comments","events_url":"https://api.github.com/repos/marceljuenemann/angular-drag-and-drop-lists/issues/52/events","html_url":"https://github.com/marceljuenemann/angular-drag-and-drop-lists/pull/52","id":60289627,"number":52,"title":"Update drop event as promise","user":{"login":"beto-rodriguez","id":10853349,"avatar_url":"https://avatars.githubusercontent.com/u/10853349?v=3","gravatar_id":"","url":"https://api.github.com/users/beto-rodriguez","html_url":"https://github.com/beto-rodriguez","followers_url":"https://api.github.com/users/beto-rodriguez/followers","following_url":"https://api.github.com/users/beto-rodriguez/following{/other_user}","gists_url":"https://api.github.com/users/beto-rodriguez/gists{/gist_id}","starred_url":"https://api.github.com/users/beto-rodriguez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beto-rodriguez/subscriptions","organizations_url":"https://api.github.com/users/beto-rodriguez/orgs","repos_url":"https://api.github.com/users/beto-rodriguez/repos","events_url":"https://api.github.com/users/beto-rodriguez/events{/privacy}","received_events_url":"https://api.github.com/users/beto-rodriguez/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-03-09T02:06:29Z","updated_at":"2015-07-28T06:44:06Z","closed_at":"2015-07-23T09:18:49Z","pull_request":{"url":"https://api.github.com/repos/marceljuenemann/angular-drag-and-drop-lists/pulls/52","html_url":"https://github.com/marceljuenemann/angular-drag-and-drop-lists/pull/52","diff_url":"https://github.com/marceljuenemann/angular-drag-and-drop-lists/pull/52.diff","patch_url":"https://github.com/marceljuenemann/angular-drag-and-drop-lists/pull/52.patch"},"body":"I needed to validate on the server before adding the element in a new list, so I made the drop event to return a promise instead. this should work as it was before but now it supports promises.\r\n\r\nnow I can\r\n\r\n```\r\n$scope.dropCallback = function (event, index, item, external, type, allowedType, collectionId) {\r\n            var deferred = $q.defer();\r\n            dataService.aoCollectionProducts.save({ productId: item.id, collectionId: collectionId }).$promise.then(function(answer) {\r\n                deferred.resolve(answer);\r\n            }, function(error) {\r\n                deferred.reject(error);\r\n            });\r\n            return deferred.promise;\r\n        };\r\n```\r\n\r\nIn my case I have a list of products and 3 shopping carts (you drag from products and drop at carts), I had some troubles to post the id of the shoping cart I could not see anyway in docs or reading the source code to easly get the database id of the cart. so I had to add a new attribute called cart-id and then I edited the invokeCallback function \r\n\r\n```\r\nfunction invokeCallback(expression, event, item) {\r\n        return $parse(expression)(scope, {\r\n          event: event,\r\n          index: getPlaceholderIndex(),\r\n          item: item || undefined,\r\n          external: !dndDragTypeWorkaround.isDragging,\r\n          type: dndDragTypeWorkaround.isDragging ? dndDragTypeWorkaround.dragType : undefined,\r\n          cartId: scope.$eval(attr.cartId)\r\n        });\r\n      }\r\n```\r\nMaybe its is necesary to add an DatabaseId attribute to the docs so it is easier to post directly to the db\r\n"},"comment":{"url":"https://api.github.com/repos/marceljuenemann/angular-drag-and-drop-lists/issues/comments/125468669","html_url":"https://github.com/marceljuenemann/angular-drag-and-drop-lists/pull/52#issuecomment-125468669","issue_url":"https://api.github.com/repos/marceljuenemann/angular-drag-and-drop-lists/issues/52","id":125468669,"user":{"login":"none-da","id":157880,"avatar_url":"https://avatars.githubusercontent.com/u/157880?v=3","gravatar_id":"","url":"https://api.github.com/users/none-da","html_url":"https://github.com/none-da","followers_url":"https://api.github.com/users/none-da/followers","following_url":"https://api.github.com/users/none-da/following{/other_user}","gists_url":"https://api.github.com/users/none-da/gists{/gist_id}","starred_url":"https://api.github.com/users/none-da/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/none-da/subscriptions","organizations_url":"https://api.github.com/users/none-da/orgs","repos_url":"https://api.github.com/users/none-da/repos","events_url":"https://api.github.com/users/none-da/events{/privacy}","received_events_url":"https://api.github.com/users/none-da/received_events","type":"User","site_admin":false},"created_at":"2015-07-28T06:44:06Z","updated_at":"2015-07-28T06:44:06Z","body":"I had a similar requirement where I am supposed to convert the dropped item into another form to push into the dropzone array. I initially used promises approach mentioned in this pull-request, but later found a much simpler alternative approach. Using angular's two way data binding. Which everyone knows anyway :smile: Here is what I did: In the drop callback I pass the containerArray and the item to be converted, once the conversion is done I manually push it to the containerArray. Since two way data binding is involved, the UI reflect the converted item. Problem solved."}}