Created
May 1, 2013 22:24
-
-
Save meskallito/5498876 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
| 'use strict'; | |
| angular.module('sherbrookeApp') | |
| .factory 'Collection', [ 'Flash', '$stateParams', 'ResourceConfig', 'Column', | |
| (Flash, params, config, Column) -> | |
| generateColumns = (alias) -> | |
| columns = _.map config[alias].collection.columns, (item) -> new Column(item) | |
| if actionsConfig = config[alias].collection.actions | |
| actionColumn = new Column 'actions', cellView: 'actions' | |
| if actionsConfig.buttons | |
| actionColumn.buttons = (r) -> | |
| r.buttonLinks ||= r._links.get(actionsConfig.buttons).change delete: { class: 'btn-danger', action: (r) -> scope.delete(r) } | |
| if actionsConfig.dropdown | |
| actionColumn.dropdown = (r) -> | |
| r.dropdownLinks ||= r._links.get actionsConfig.dropdown | |
| columns.push actionColumn | |
| columns | |
| { | |
| extend: (scope) -> | |
| scope.delete = (r) -> | |
| Flash.add info: 'Record was deleted' | |
| r.$delete params, -> scope.$broadcast 'itemRemoved', scope.items.indexOf(r) | |
| scope.next = (link) -> | |
| items = scope.model.query angular.extend({ page: link.page }, params), (data)-> | |
| scope.$broadcast('pageAdded', items) | |
| scope.paginationLinks = data._links.get('next').change next: { action: (l) -> scope.next(l) } | |
| scope.items = scope.model.query (data)-> | |
| scope.actionLinks = data._links.get('new') | |
| scope.paginationLinks = data._links.get('next').change next: { action: (l) -> scope.next(l) } | |
| scope.columns = generateColumns(scope.model.alias.object) | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment