1
1
' use strict'
2
2
3
- SubmitWorkVisualController = ($scope , SubmitWorkAPIService , API_URL ) ->
4
- vm = this
5
- vm .loading = true
6
- vm .workId = $scope . workId
3
+ SubmitWorkVisualController = ($scope , $rootScope , $state , SubmitWorkService , Optimist , API_URL ) ->
4
+ vm = this
5
+ vm .workId = $scope . workId
6
+ vm .loading = true
7
7
vm .visualsUploaderUploading = null
8
8
vm .visualsUploaderHasErrors = null
9
-
10
- vm .work =
11
- name : null
12
- requestType : null
13
- summary : null
14
- features : []
15
- featuresDetails : null
16
-
17
- vm .visualDesign = {}
18
- vm .visualDesign .fonts = [
9
+ vm .showPaths = true
10
+ vm .showChooseStylesModal = false
11
+ vm .showUploadStylesModal = false
12
+ vm .showUrlStylesModal = false
13
+ vm .activeStyleModal = null
14
+ vm .nextButtonDisabled = false
15
+ vm .backButtonDisabled = false
16
+ vm .styleModals = [' fonts' , ' colors' , ' icons' ]
17
+
18
+ config = {}
19
+ config .fonts = [
19
20
name : ' Serif'
20
- description : ' a small line attached to the end of a stroke'
21
- id : ' 1234'
21
+ description : ' Classic design, good legiblity for large and small text.'
22
+ id : ' 123'
23
+ selected : false
22
24
,
23
25
name : ' Sans Serif'
24
- description : ' does not have the small `serifs`'
25
- id : ' 1235'
26
- ,
27
- name : ' Slap Serif'
28
- description : ' does not have the small `serifs`'
29
- id : ' 1236'
30
- ,
31
- name : ' Script'
32
- description : ' does not have the small `serifs`'
33
- id : ' 1237'
34
- ,
35
- name : ' Grunge'
36
- description : ' does not have the small `serifs`'
37
- id : ' 1238'
26
+ id : ' 456'
27
+ description : ' Modern design, good for headers and body text.'
28
+ selected : false
38
29
]
39
30
40
- vm . visualDesign .colors = [
31
+ config .colors = [
41
32
name : ' Palette 1'
42
33
description : ' Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
43
34
id : ' 1234'
35
+ selected : false
44
36
,
45
37
name : ' Palette 2'
46
38
description : ' Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
47
39
id : ' 1235'
40
+ selected : false
41
+
48
42
,
49
43
name : ' Palette 3'
50
44
description : ' Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
51
45
id : ' 1236'
46
+ selected : false
47
+
52
48
,
53
49
name : ' Palette 4'
54
50
description : ' Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
55
51
id : ' 1237'
56
- ,
57
- name : ' Palette 5'
58
- description : ' Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
59
- id : ' 1238'
52
+ selected : false
60
53
]
61
54
62
- vm . visualDesign .icons = [
63
- name : ' Google '
55
+ config .icons = [
56
+ name : ' Flat Colors '
64
57
description : ' Lorem ipsum dolor sit amet'
65
58
id : ' 1234'
59
+ selected : false
60
+
66
61
,
67
- name : ' Anamorphic '
62
+ name : ' Thin Line '
68
63
description : ' Lorem ipsum dolor sit amet'
69
64
id : ' 1235'
65
+ selected : false
66
+
70
67
,
71
- name : ' iOS Style '
68
+ name : ' Solid Line '
72
69
description : ' Lorem ipsum dolor sit amet'
73
70
id : ' 1236'
74
- ,
75
- name : ' Android'
76
- description : ' Lorem ipsum dolor sit amet'
77
- id : ' 1237'
78
- ,
79
- name : ' Windows 8'
80
- description : ' Lorem ipsum dolor sit amet'
81
- id : ' 1238'
71
+ selected : false
82
72
]
83
73
84
- vm .save = (onSuccess ) ->
85
- if vm .workId
86
- params =
87
- id : vm .workId
88
-
89
- resource = SubmitWorkAPIService .put params, vm .work
90
- resource .$promise .then (response) ->
91
- onSuccess? response
92
- resource .$promise .catch (response) ->
93
- # TODO: add error handling
94
-
95
- vm .submitVisuals = ->
96
- workFonts = vm .work .visualDesign .fonts
97
- workColors = vm .work .visualDesign .colors
98
- workIcons = vm .work .visualDesign .icons
74
+ vm .showChooseStyles = ->
75
+ vm .showPaths = false
76
+ vm .showChooseStylesModal = true
77
+ vm .backButtonDisabled = true
78
+ vm .activateModal (' fonts' )
79
+
80
+ vm .showUploadStyles = ->
81
+ vm .showUploadStylesModal = true
82
+
83
+ vm .showUrlStyles = ->
84
+ vm .showUrlStylesModal = true
85
+
86
+ vm .activateModal = (modal ) ->
87
+ vm .activeStyleModal = modal
88
+ updateButtons ()
89
+
90
+ vm .viewNext = ->
91
+ currentIndex = vm .styleModals .indexOf vm .activeStyleModal
92
+ isValid = currentIndex < vm .styleModals .length - 1
93
+ if isValid
94
+ nextModal = vm .styleModals [currentIndex + 1 ]
95
+ vm .activateModal (nextModal)
96
+
97
+ vm .viewPrevious = ->
98
+ currentIndex = vm .styleModals .indexOf vm .activeStyleModal
99
+ isValid = currentIndex > 0
100
+ if isValid
101
+ previousModal = vm .styleModals [currentIndex - 1 ]
102
+ vm .activateModal (previousModal)
103
+
104
+ vm .save = ->
105
+ visualsValid = visualDesignValid ()
106
+ updates = getUpdates ()
107
+ if visualsValid
108
+ SubmitWorkService .save (updates).then ->
109
+ $state .go (" submit-work-development" )
110
+
111
+ visualDesignValid = ->
112
+ updates = getUpdates ()
99
113
uploaderValid = ! vm .visualsUploaderUploading && ! vm .visualsUploaderHasErrors
114
+ # TODO: add updates.colors check
115
+ hasVisualChoices = updates .font && updates .icons
116
+ # check if visuals are selected or entered via url
117
+ hasVisuals = hasVisualChoices || updates .url
118
+ hasVisuals
119
+
120
+ getUpdates = ->
121
+ updates =
122
+ font : vm .work .font
123
+ colors : vm .work .colors
124
+ icons : vm .work .icons
125
+ url : null
126
+
127
+ if vm .work .url
128
+ updates .url = vm .visualDesign .url
129
+
130
+ updates
131
+
132
+ vm .navigateDevelopment = ->
133
+ visualsValid = visualsValid ()
134
+ if visualsValid
135
+ $state .go (" submit-work-development" )
136
+
137
+ updateButtons = ->
138
+ currentIndex = vm .styleModals .indexOf vm .activeStyleModal
139
+ isFirst = currentIndex == 0
140
+ isLast = currentIndex == vm .styleModals .length - 1
141
+ if isFirst
142
+ vm .backButtonDisabled = true
143
+ else if isLast
144
+ vm .nextButtonDisabled = true
145
+ vm .showFinishDesignButton = true
146
+ else
147
+ vm .nextButtonDisabled = false
148
+ vm .backButtonDisabled = false
149
+ vm .showFinishDesignButton = false
100
150
101
- if workFonts .length && workColors .length && workIcons .length
102
- # TODO: replace with proper status
103
- vm .work .status = ' visualsAdded'
104
- vm .save (response) ->
105
- # TODO: navigate to "development" view
106
-
107
- mockify = (work ) ->
108
- work .visualDesign = {}
109
- work .visualDesign .fonts = []
110
- work .visualDesign .colors = []
111
- work .visualDesign .icons = []
112
151
113
152
configureUploader = ->
114
153
assetType = ' specs'
@@ -123,31 +162,51 @@ SubmitWorkVisualController = ($scope, SubmitWorkAPIService, API_URL) ->
123
162
workId : vm .workId
124
163
assetType : assetType
125
164
126
- activate = ->
127
- configureUploader ()
128
- if vm .workId
129
- params =
130
- id : vm .workId
165
+ onChange = ->
166
+ if SubmitWorkService .work .o .hasPending
167
+ return false
168
+
169
+ vm .loading = false
170
+
171
+ # TODO: Remove mock data once visualDesign is in payload
172
+ SubmitWorkService .work .visualDesign = {}
173
+ SubmitWorkService .work .visualDesign .url = null
174
+ SubmitWorkService .work .visualDesign .font =
175
+ id : ' 123'
176
+ SubmitWorkService .work .visualDesign .colors =
177
+ id : ' 1236'
178
+ SubmitWorkService .work .visualDesign .icons =
179
+ id : ' 1234'
180
+ # initialize vm
181
+ unless vm .visualDesign
182
+ vm .visualDesign = config
183
+ vm .visualDesign .fonts = config .fonts
184
+ vm .visualDesign .colors = config .colors
185
+ vm .visualDesign .icons = config .icons
186
+
187
+ vm .work = {}
188
+ vm .work .icons = SubmitWorkService .work .visualDesign .icons
189
+ vm .work .colors = SubmitWorkService .work .visualDesign .colors
190
+ vm .work .font = SubmitWorkService .work .visualDesign .font
191
+ vm .work .url = null
131
192
132
- resource = SubmitWorkAPIService .get params
133
193
134
- resource .$promise .then (response) ->
135
- vm .work = response
136
- # TODO: remove once all properties are in payload
137
- mockify vm .work
194
+ activate = ->
195
+ destroyWorkListener = $rootScope .$on " SubmitWorkService.work:changed" , ->
196
+ onChange ()
138
197
139
- resource . $promise . catch (response) ->
140
- # TODO: add error handling
198
+ $scope . $on ' $destroy ' , ->
199
+ destroyWorkListener ()
141
200
142
- resource . $promise . finally ->
143
- vm . loading = false
144
- else
145
- vm . loading = false
201
+ SubmitWorkService . fetch ( vm . workId )
202
+ configureUploader ()
203
+ # TODO: remove once work gets fetched
204
+ onChange ()
146
205
147
206
vm
148
207
149
208
activate ()
150
209
151
- SubmitWorkVisualController .$inject = [' $scope' , ' SubmitWorkAPIService ' , ' API_URL' ]
210
+ SubmitWorkVisualController .$inject = [' $scope' , ' $rootScope ' , ' $state ' , ' SubmitWorkService ' , ' Optimist ' , ' API_URL' ]
152
211
153
212
angular .module (' appirio-tech-ng-submit-work' ).controller ' SubmitWorkVisualController' , SubmitWorkVisualController
0 commit comments