mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
New pattern: blank Options for index drop down filters are added within service
Rather than in the controller after data is loaded
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
angular.module("admin.enterprises").factory 'Enterprises', ($q, EnterpriseResource) ->
|
||||
angular.module("admin.enterprises").factory 'Enterprises', ($q, EnterpriseResource, blankOption) ->
|
||||
new class Enterprises
|
||||
enterprisesByID: {}
|
||||
pristineByID: {}
|
||||
|
||||
index: (params={}, callback=null) ->
|
||||
EnterpriseResource.index params, (data) =>
|
||||
includeBlank = !!params['includeBlank']
|
||||
delete params['includeBlank']
|
||||
EnterpriseResource.index(params, (data) =>
|
||||
for enterprise in data
|
||||
@enterprisesByID[enterprise.id] = enterprise
|
||||
@pristineByID[enterprise.id] = angular.copy(enterprise)
|
||||
|
||||
(callback || angular.noop)(data)
|
||||
|
||||
data.unshift(blankOption()) if includeBlank
|
||||
data
|
||||
)
|
||||
|
||||
save: (enterprise) ->
|
||||
deferred = $q.defer()
|
||||
enterprise.$update({id: enterprise.permalink})
|
||||
|
||||
Reference in New Issue
Block a user