|
| 1 | +/* |
| 2 | + * Copyright (c) 2019, Ford Motor Company All rights reserved. |
| 3 | + * |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions are met: |
| 6 | + * · Redistributions of source code must retain the above copyright notice, |
| 7 | + * this list of conditions and the following disclaimer. |
| 8 | + * · Redistributions in binary form must reproduce the above copyright notice, |
| 9 | + * this list of conditions and the following disclaimer in the documentation |
| 10 | + * and/or other materials provided with the distribution. |
| 11 | + * · Neither the name of the Ford Motor Company nor the names of its |
| 12 | + * contributors may be used to endorse or promote products derived from this |
| 13 | + * software without specific prior written permission. |
| 14 | + * |
| 15 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 19 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 | + * POSSIBILITY OF SUCH DAMAGE. |
| 26 | + */ |
| 27 | +/** |
| 28 | + * @name SDL.ServiceUpdatePopUp |
| 29 | + * @desc Service update pop up module visual representation |
| 30 | + * @category View |
| 31 | + * @filesource app/view/sdl/ServiceUpdatePopUp.js |
| 32 | + * @version 1.0 |
| 33 | + */ |
| 34 | + |
| 35 | +SDL.ServiceUpdatePopUp = Em.ContainerView.create( |
| 36 | + { |
| 37 | + elementId: 'ServiceUpdatePopUp', |
| 38 | + classNames: 'ServiceUpdatePopUp', |
| 39 | + classNameBindings: [ |
| 40 | + 'active' |
| 41 | + ], |
| 42 | + childViews: [ |
| 43 | + 'message', |
| 44 | + 'progressIndicatorView', |
| 45 | + 'backButton', |
| 46 | + 'serviceEventLabel', |
| 47 | + 'serviceTypeLabel', |
| 48 | + 'serviceReasonLabel' |
| 49 | + ], |
| 50 | + |
| 51 | + timer: null, |
| 52 | + active: false, |
| 53 | + content: '', |
| 54 | + progress: false, |
| 55 | + serviceEventContent: '', |
| 56 | + serviceTypeContent: '', |
| 57 | + serviceReasonContent: '', |
| 58 | + |
| 59 | + progressIndicatorView: Em.View.extend( |
| 60 | + { |
| 61 | + elementId: 'progress', |
| 62 | + classNameBindings: 'this.parentView.progress:progress' |
| 63 | + } |
| 64 | + ), |
| 65 | + backButton: SDL.Button.extend( |
| 66 | + { |
| 67 | + classNames: 'button backButton', |
| 68 | + text: 'X', |
| 69 | + click: function() { |
| 70 | + this._parentView.deactivate(); |
| 71 | + }, |
| 72 | + buttonAction: true, |
| 73 | + onDown: false |
| 74 | + } |
| 75 | + ), |
| 76 | + message: SDL.Label.extend( |
| 77 | + { |
| 78 | + elementId: 'text', |
| 79 | + classNames: 'text', |
| 80 | + contentBinding: 'parentView.content' |
| 81 | + } |
| 82 | + ), |
| 83 | + serviceEventLabel: SDL.Label.extend( |
| 84 | + { |
| 85 | + elementId: 'serviceEventLabel', |
| 86 | + classNames: 'serviceEventLabel', |
| 87 | + contentBinding: 'parentView.serviceEventContent' |
| 88 | + } |
| 89 | + ), |
| 90 | + serviceTypeLabel: SDL.Label.extend( |
| 91 | + { |
| 92 | + elementId: 'serviceTypeLabel', |
| 93 | + classNames: 'serviceTypeLabel', |
| 94 | + contentBinding: 'parentView.serviceTypeContent' |
| 95 | + } |
| 96 | + ), |
| 97 | + serviceReasonLabel: SDL.Label.extend( |
| 98 | + { |
| 99 | + elementId: 'serviceReasonLabel', |
| 100 | + classNames: 'serviceReasonLabel', |
| 101 | + contentBinding: 'parentView.serviceReasonContent' |
| 102 | + } |
| 103 | + ), |
| 104 | + |
| 105 | + /** |
| 106 | + * @function deactivate |
| 107 | + * @desc Deactivate ServiceUpdatePopUp |
| 108 | + * |
| 109 | + */ |
| 110 | + deactivate: function() { |
| 111 | + this.set('active', false); |
| 112 | + this.set('progress', false); |
| 113 | + this.set('content', ''); |
| 114 | + this.set('infoContent', ''); |
| 115 | + this.set('serviceTypeContent', ''); |
| 116 | + this.set('serviceEventContent', ''); |
| 117 | + this.set('serviceReasonContent', ''); |
| 118 | + }, |
| 119 | + |
| 120 | + setLogMessage: function(serviceType, serviceEvent, serviceReason) { |
| 121 | + this.set('serviceTypeContent', serviceType ? 'Service type: ' + serviceType : ''); |
| 122 | + this.set('serviceEventContent', serviceEvent ? 'Service event: ' + serviceEvent : ''); |
| 123 | + this.set('serviceReasonContent', serviceReason ? 'Service reason: ' + serviceReason : ''); |
| 124 | + }, |
| 125 | + /** |
| 126 | + * @function activate |
| 127 | + * @desc activate ServiceUpdatePopUp |
| 128 | + * @param {string} serviceType |
| 129 | + * @param {string} serviceEvent |
| 130 | + * @param {string} serviceReason |
| 131 | + */ |
| 132 | + activate: function(serviceType, serviceEvent, serviceReason) { |
| 133 | + if(serviceType === undefined) { |
| 134 | + return; |
| 135 | + } |
| 136 | + this.setLogMessage(serviceType, serviceEvent, serviceReason); |
| 137 | + switch (serviceEvent) { |
| 138 | + case 'REQUEST_RECEIVED': { |
| 139 | + this.setContentByServiceType(serviceType); |
| 140 | + this.set('progress', this.get('content') != ''); |
| 141 | + this.set('active', this.get('content') != ''); |
| 142 | + break; |
| 143 | + } |
| 144 | + case 'REQUEST_ACCEPTED': { |
| 145 | + var self = this; |
| 146 | + this.timer = setTimeout( |
| 147 | + function() { |
| 148 | + self.deactivate(); |
| 149 | + }, |
| 150 | + 2000 |
| 151 | + ); |
| 152 | + break; |
| 153 | + } |
| 154 | + case 'REQUEST_REJECTED': { |
| 155 | + this.rejectedRequest(serviceReason); |
| 156 | + var self = this; |
| 157 | + this.timer = setTimeout( |
| 158 | + function() { |
| 159 | + self.deactivate(); |
| 160 | + }, |
| 161 | + 5000 |
| 162 | + ); |
| 163 | + break; |
| 164 | + } |
| 165 | + default: { |
| 166 | + if(serviceReason !== undefined) { |
| 167 | + this.rejectedRequest(serviceReason); |
| 168 | + var self = this; |
| 169 | + this.timer = setTimeout( |
| 170 | + function() { |
| 171 | + self.deactivate(); |
| 172 | + }, |
| 173 | + 5000 |
| 174 | + ); |
| 175 | + } |
| 176 | + break; |
| 177 | + } |
| 178 | + } |
| 179 | + }, |
| 180 | + |
| 181 | + /** |
| 182 | + * @function setContentByServiceType |
| 183 | + * @param {string} serviceType |
| 184 | + * @description Check serviceType and set content of popUp |
| 185 | + */ |
| 186 | + setContentByServiceType: function(serviceType) { |
| 187 | + switch(serviceType) { |
| 188 | + case 'VIDEO': { |
| 189 | + this.set('content', 'Starting Video Stream'); |
| 190 | + break; |
| 191 | + } |
| 192 | + case 'AUDIO': { |
| 193 | + this.set('content', 'Starting Audio Stream'); |
| 194 | + break; |
| 195 | + } |
| 196 | + default: break; |
| 197 | + } |
| 198 | + }, |
| 199 | + |
| 200 | + /** |
| 201 | + * @function rejectedRequest |
| 202 | + * @desc Processing reason of rejected request |
| 203 | + * @param {string} reason |
| 204 | + */ |
| 205 | + rejectedRequest: function(reason) { |
| 206 | + this.set('active', true); |
| 207 | + this.set('progress',false); |
| 208 | + |
| 209 | + switch(reason) { |
| 210 | + case 'PTU_FAILED': { |
| 211 | + this.set('content', 'Unable to update apps.' + |
| 212 | + 'Make sure your device has an internet connection'); |
| 213 | + break; |
| 214 | + } |
| 215 | + case 'INVALID_CERT': { |
| 216 | + this.set('content', 'System is unable to authenticate the app'); |
| 217 | + break; |
| 218 | + } |
| 219 | + case 'INVALID_TIME': { |
| 220 | + this.set('content', 'Unable to get valid time.' + |
| 221 | + 'Make sure your device has access to GPS signal'); |
| 222 | + break; |
| 223 | + } |
| 224 | + case 'PROTECTION_ENFORCED': { |
| 225 | + this.set('content', 'Attempting to start unprotected service which ' |
| 226 | + + 'is configured as a force protected'); |
| 227 | + break; |
| 228 | + } |
| 229 | + case 'PROTECTION_DISABLED': { |
| 230 | + this.set('content', 'Attempting to start protected service which ' |
| 231 | + + 'is configured as force unprotected'); |
| 232 | + break; |
| 233 | + } |
| 234 | + default: { |
| 235 | + this.set('content', 'Rejected by unknown reason'); |
| 236 | + break; |
| 237 | + } |
| 238 | + } |
| 239 | + } |
| 240 | + } |
| 241 | +); |
| 242 | + |
0 commit comments