|
67 | 67 |
|
68 | 68 | /** |
69 | 69 | * Fetch the template from the service. |
70 | | - * TODO: Implement promises. |
71 | 70 | */ |
72 | 71 | function fetchSpecTemplate() { |
73 | 72 |
|
|
77 | 76 | var getTemplateUrl = getCurrentUrl() + 'gettemplate'; |
78 | 77 |
|
79 | 78 | // Fetch the template and then insert it into the current document's body. |
80 | | - // httpGetAsync(getTemplateUrl, insertFileIntoBody); |
81 | | - |
82 | | - // httpGetAsync(getTemplateUrl) |
83 | | - // .then(insertFileIntoBody(results)) |
84 | | - // .catch(function(error) { |
85 | | - // console.log('Error: ' + JSON.stringify(error)); |
86 | | - // }); |
87 | | - |
88 | 79 | var urlPromise = httpGetAsync(getTemplateUrl); |
89 | | - |
90 | 80 | urlPromise.then(insertFileIntoBody) |
91 | 81 | .catch(function(err) { |
92 | 82 | console.log('Error: ' + err); |
|
125 | 115 |
|
126 | 116 | /** |
127 | 117 | * Gets a JSON document that contains a blacklist of words. |
128 | | - * |
129 | | - * TODO: Implement promises. |
130 | 118 | */ |
131 | 119 | function getBlackList() { |
132 | 120 |
|
|
141 | 129 |
|
142 | 130 | // Call the service to get the blacklist, and then cache it in |
143 | 131 | // localStorage, then return the promise. |
144 | | - // httpGetAsync(getBlacklistUrl, function(json) { |
145 | | - // localStorage.setItem('badwordcache', json); |
146 | | - // }); |
147 | 132 | return httpGetAsync(getBlacklistUrl) |
148 | 133 | .then(function(json) { |
149 | 134 | localStorage.setItem('badwordcache', json); |
|
154 | 139 | /** |
155 | 140 | * Gets the boilerplate text. This demonstrates how to initialize the |
156 | 141 | * current document with boilerplate stored in a service. |
157 | | - * |
158 | | - * TODO: Implement promises. |
159 | 142 | */ |
160 | 143 | function getBoilerplate() { |
161 | 144 |
|
|
166 | 149 |
|
167 | 150 | // Call the service to get the boilerplate and add it to localStorage, |
168 | 151 | // then return the promise. |
169 | | - // httpGetAsync(getBoilerplateUrl, function(json) { |
170 | | - |
171 | | - // // Put the array of bad words into local storage so that we can |
172 | | - // // access them. |
173 | | - // localStorage.setItem('boilerplate', json); |
174 | | - // var boilerplate = JSON.parse(json); |
175 | | - |
176 | | - // var elements = boilerplate.elements; |
177 | | - |
178 | | - // // Add the boilerplate names to the drop down. |
179 | | - // for (var i = 0; i < elements.length; i++) { |
180 | | - // $('#boilerplateDropdown').append(new Option(elements[i].name, |
181 | | - // elements[i].name)); |
182 | | - // } |
183 | | - |
184 | | - // // Initialize stylized fabric UI for dropdown and call the dropdown |
185 | | - // // function to populate dropdown with values. You need to call this |
186 | | - // // when you update contents of a dropdown. |
187 | | - // $(".ms-Dropdown").Dropdown(); |
188 | | - // }); |
189 | 152 | return httpGetAsync(getBoilerplateUrl) |
190 | 153 | .then(function(json) { |
191 | 154 |
|
|
211 | 174 |
|
212 | 175 | /** |
213 | 176 | * Save the current boilerplate state with the services. |
214 | | - * |
215 | | - * TODO: Implement promises. |
216 | 177 | **/ |
217 | 178 | function saveBoilerplate() { |
218 | 179 |
|
|
223 | 184 |
|
224 | 185 | var boilerplate = localStorage.getItem('boilerplate'); |
225 | 186 |
|
226 | | - // httpPostAsync(postBoilerplateUrl, boilerplate, function() { |
227 | | - // console.log('Posted the boilerplate back to the service.') |
228 | | - // }); |
229 | | - |
230 | 187 | httpPostAsync(postBoilerplateUrl, boilerplate) |
231 | 188 | .then(function(value) { |
232 | 189 | console.log(value); |
|
239 | 196 | /** |
240 | 197 | * GET helper to call a service. |
241 | 198 | * |
242 | | - * TODO: Implement promises. |
243 | | - * |
244 | 199 | * @param theUrl {string} The URL of the service. |
245 | 200 | * @param callback {function} The callback function. |
246 | 201 | */ |
247 | | - // function httpGetAsync(theUrl, callback) { |
248 | | - // var request = new XMLHttpRequest(); |
249 | | - // request.open("GET", theUrl, true); |
250 | | - // request.onreadystatechange = function() { |
251 | | - // if (request.readyState === 4 && request.status === 200) |
252 | | - // callback(request.responseText); |
253 | | - // } |
254 | | - // request.send(null); |
255 | | - // } |
256 | | - |
257 | | - // function httpGetAsync(url) { |
258 | | - // var request = new XMLHttpRequest(); |
259 | | - // var deferred = Q.defer(); |
260 | | - |
261 | | - // request.open("GET", url, true); |
262 | | - // // request.onreadystatechange = onreadystatechange; |
263 | | - // request.onload = onload; |
264 | | - // request.onerror = onerror; |
265 | | - // request.send(null); |
266 | | - |
267 | | - // // function onreadystatechange() { |
268 | | - // // if (request.readyState === 4 && request.status === 200) { |
269 | | - // // deferred.resolve(request.responseText); |
270 | | - // // } else { |
271 | | - // // deferred.reject(new Error('Status code: ' + request.status)); |
272 | | - // // } |
273 | | - |
274 | | - // // } |
275 | | - |
276 | | - // function onload() { |
277 | | - // if (request.status === 200) { |
278 | | - // deferred.resolve(request.responseText); |
279 | | - // } else { |
280 | | - // deferred.reject(new Error('Status code: ' + request.status)); |
281 | | - // } |
282 | | - // } |
283 | | - |
284 | | - // function onerror() { |
285 | | - // deferred.reject(new Error('Status code: ' + request.status)); |
286 | | - // } |
287 | | - |
288 | | - // return deferred.promise; |
289 | | - // } |
290 | | - |
291 | 202 | function httpGetAsync(url) { |
292 | 203 |
|
293 | 204 | return Q.Promise(function(resolve, reject) { |
|
316 | 227 | /** |
317 | 228 | * POST helper to call a service. |
318 | 229 | * |
319 | | - * TODO: Implement promises. |
320 | | - * |
321 | 230 | * @param theUrl {string} The URL of the service. |
322 | 231 | * @param payload {string} The JSON payload. |
323 | 232 | * @param callback {function} The callback function. |
324 | 233 | */ |
325 | | - // function httpPostAsync(theUrl, payload, callback) { |
326 | | - // var request = new XMLHttpRequest(); |
327 | | - |
328 | | - // request.open("POST", theUrl, true); |
329 | | - // request.setRequestHeader("Content-type", "application/json"); |
330 | | - // request.onreadystatechange = function() { |
331 | | - // if (request.readyState === 4 && request.status === 200) |
332 | | - // callback(request.responseText); |
333 | | - // } |
334 | | - // request.send(payload); |
335 | | - // } |
336 | | - |
337 | 234 | function httpPostAsync(url, payload) { |
338 | 235 | var request = new XMLHttpRequest(); |
339 | 236 | var deferred = Q.defer(); |
|
0 commit comments