|
120 | 120 | var other_purpose = form.find('#id_purpose_text'); |
121 | 121 | var deadline = form.find('#id_deadline_date'); |
122 | 122 | var other_organization = form.find('#id_other_organization'); |
| 123 | + var approval = form.find('#id_approval'); |
123 | 124 | var config = {}; |
124 | 125 |
|
125 | 126 | var readConfig = function() { |
126 | 127 | var confcontainer = form.find('.formconfig'); |
127 | | - config.poc_update_url = confcontainer.find('.poc_update_url').text(); |
128 | | - config.cc_update_url = confcontainer.find('.cc_update_url').text(); |
| 128 | + config.info_update_url = confcontainer.find('.info_update_url').text(); |
129 | 129 | }; |
130 | 130 |
|
131 | 131 | var render_mails_into = function(container, person_list) { |
|
137 | 137 | container.html(html); |
138 | 138 | }; |
139 | 139 |
|
140 | | - var updatePOC = function() { |
141 | | - var entity = organization.find('option:selected'); |
142 | | - var url = config.poc_update_url; |
143 | | - $.ajax({ |
144 | | - url: url, |
145 | | - type: 'GET', |
146 | | - cache: false, |
147 | | - async: true, |
148 | | - dataType: 'json', |
149 | | - data: {entity_id: entity.val()}, |
150 | | - success: function(response){ |
151 | | - if (!response.error) { |
152 | | - render_mails_into(poc, response.poc); |
153 | | - } |
154 | | - } |
155 | | - }); |
156 | | - return false; |
| 140 | + var toggleApproval = function(needed) { |
| 141 | + if (!approval.length) { |
| 142 | + return; |
| 143 | + } |
| 144 | + if (needed) { |
| 145 | + approval.removeAttr('disabled'); |
| 146 | + approval.removeAttr('checked'); |
| 147 | + } else { |
| 148 | + approval.attr('checked','checked'); |
| 149 | + approval.attr('disabled','disabled'); |
| 150 | + } |
157 | 151 | }; |
158 | 152 |
|
159 | | - var updateCC = function() { |
160 | | - var entity = organization.find('option:selected'); |
161 | | - var sdo = from.find('option:selected'); |
162 | | - var url = config.cc_update_url; |
| 153 | + var updateInfo = function() { |
| 154 | + var entity = organization; |
| 155 | + var to_entity = from; |
| 156 | + var url = config.info_update_url; |
163 | 157 | $.ajax({ |
164 | 158 | url: url, |
165 | 159 | type: 'GET', |
166 | 160 | cache: false, |
167 | 161 | async: true, |
168 | 162 | dataType: 'json', |
169 | 163 | data: {to_entity_id: organization.val(), |
170 | | - from_entity_id: sdo.val()}, |
| 164 | + from_entity_id: to_entity.val()}, |
171 | 165 | success: function(response){ |
172 | 166 | if (!response.error) { |
173 | 167 | render_mails_into(cc, response.cc); |
| 168 | + render_mails_into(poc, response.poc); |
| 169 | + toggleApproval(response.needs_approval); |
174 | 170 | } |
175 | 171 | } |
176 | 172 | }); |
|
185 | 181 | var updatePurpose = function() { |
186 | 182 | var datecontainer = deadline.parents('.field'); |
187 | 183 | var othercontainer = other_purpose.parents('.field'); |
188 | | - var selected_id = purpose.find('option:selected').val(); |
| 184 | + var selected_id = purpose.val(); |
189 | 185 | var deadline_required = datecontainer.find('.fieldRequired'); |
190 | 186 |
|
191 | 187 | if (selected_id == '1' || selected_id == '2' || selected_id == '5') { |
|
206 | 202 | }; |
207 | 203 |
|
208 | 204 | var checkOtherSDO = function() { |
209 | | - var entity = organization.find('option:selected').val(); |
| 205 | + var entity = organization.val(); |
210 | 206 | if (entity=='othersdo') { |
211 | 207 | other_organization.parents('.field').show(); |
212 | 208 | } else { |
|
215 | 211 | }; |
216 | 212 |
|
217 | 213 | var initTriggers = function() { |
218 | | - organization.change(updatePOC); |
219 | | - organization.change(updateCC); |
| 214 | + organization.change(updateInfo); |
| 215 | + organization.change(updateInfo); |
220 | 216 | organization.change(checkOtherSDO); |
221 | | - from.change(updateCC); |
| 217 | + from.change(updateInfo); |
222 | 218 | reply.keyup(updateFrom); |
223 | 219 | purpose.change(updatePurpose); |
224 | 220 | }; |
225 | 221 |
|
226 | 222 | var updateOnInit = function() { |
227 | 223 | updateFrom(); |
228 | | - updateCC(); |
229 | | - updatePOC(); |
| 224 | + updateInfo(); |
230 | 225 | updatePurpose(); |
231 | 226 | checkOtherSDO(); |
232 | 227 | }; |
|
0 commit comments