Created
April 3, 2014 10:12
-
-
Save jkyamog/9951961 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def.factory app.Product [$resource] | |
($resource "/products/:id" (obj :id "@id"))) | |
(def.controller app.ProductController [$scope Product] | |
(! $scope.products (. Product query)) | |
(! $scope.updateProduct (fn [product] | |
(. product $save))) | |
(! $scope.deleteProduct (fn [product] | |
(. product $remove | |
(fn [] | |
($scope.products.splice ($scope.products.indexOf product) 1)))))) | |
(def.controller app.ProductCreateController [$scope Product] | |
(! $scope.save (fn [] | |
(let [product (new Product (obj :name $scope.product.name | |
:description $scope.product.description | |
:quantity (js/parseInt $scope.product.quantity)))] | |
(. product $save (fn [data] | |
($scope.products.push data) | |
(! $scope.product nil))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment