1App.EventorRoute = App.AuthenticatedRoute.extend({ 2 model: function(params) { 3 var self = this; 4 var applicationController = this.controllerFor('application'); 5 6 if (parseInt(params.eventor_id)) { 7 8 return this.store.fetchById('eventor', params.eventor_id).then(null, function (reason) { 9 self.controllerFor('application').error404(reason, { 10 title: 'Ooops! An "event not found" error occurred', 11 text: 'The event entry you tried to edit either does not exist or is not available!', 12 back: 'eventors' 13 }); 14 self.destroyRecord(); 15 }); 16 } else { 17 var eventor = this.store.createRecord('eventor', { 18 title: 'New event', 19 bccEmails: '', 20 publishStatus: true, 21 registAsComp: true, 22 registAsPers: true, 23 bccToContact: true 24 }); 25 26 // Create a new location with location description for each language, and an event description 27 try { 28 var newLocationDescs = Ember.A(); 29 var newDescs = Ember.A(); 30 this.store.all('language').forEach(function (language) { 31 newLocationDescs.pushObject(self.store.createRecord('eventorLocationDesc', { 32 locTitle: '[' + language.get('lang') + '] New location...', 33 lang: language.get('lang') 34 })); 35 newDescs.pushObject(self.store.createRecord('eventorDesc', { 36 lang: language.get('lang'), 37 })); 38 }); 39 40 var newLocation = this.store.createRecord('eventorLocation', { 41 locStreet: '', 42 locPostCode: '' 43 }); 44 45 newLocation.get('eventorLocationDescs').pushObjects(newLocationDescs); 46 47 // Preloaded! 48 eventor.set('countries', applicationController.get('selectedOrganizer').get('organizerCountries')); 49 eventor.set('currencies', applicationController.get('selectedOrganizer').get('organizerCurrencies')); 50 eventor.set('timezones', applicationController.get('selectedOrganizer').get('organizerTimezones')); 51 52 eventor.set('languages', this.store.all('language')); 53 eventor.set('contacts', this.store.all('contact')); 54 eventor.set('bankAccounts', this.store.all('bankAccount')); 55 eventor.set('bankAccount', this.store.all('bankAccount').filterBy('defaultBankAccount', true).objectAt(0)); 56 eventor.get('eventorLanguages').pushObjects(this.store.all('language')); 57 58 // Others... 59 eventor.set('eventorLocation', newLocation); 60 eventor.get('eventorDescs').pushObjects(newDescs); 61 } catch (e) { 62 console.log(e); 63 } 64 65 return eventor; 66 } 67 }, 68 setupController: function(controller, model) { 69 controller.set('model', model); 70 71 // Set breadcrumbs 72 if (model.get('isNew')) { 73 controller.set('breadcrumbTitle', 'Add event'); 74 controller.set('boolId', false); 75 } else { 76 controller.set('breadcrumbTitle', model.get('description.title')); 77 controller.set('boolId', true); 78 } 79 80 model.set( 'description', model.get('eventorDescs').filterBy('lang', model.get('eventorLanguages.firstObject.lang')).objectAt(0) ); 81 } 82}); 83 84App.EventorEditRoute = App.AuthenticatedRoute.extend({ 85 controllerName: 'eventorEdit', 86 activate: function() { 87 $(document).attr('title', 'EventER | Events | Edit event'); 88 }, 89 afterModel: function (model) { 90 // TODO: This is a nasty fix for J-introduced bug (in optimization rewrite)
90where getting sth like: ".map of undefined" 91 if(parseInt(model.get('id'))) 92 model.reload(); 93 94 // Get controllers 95 var application = this.controllerFor('application'); 96 var controller = this.controllerFor('eventorEdit'); 97 var self = this; 98 99 // Set edit languages 100 application.set('editLanguages', model.get('eventorLanguages')); 101 102 // Get edit lang 103 var editLang = application.getEditLanguage(controller.get('editLang')); 104 105 // Set edit languages 106 application.setEditLanguages(model, editLang, 'eventor'); 107 108 // Set description 109 application.getOrCreateDesc(model, editLang, 'eventor'); 110 111 // Do manipulation of locations (not covered by functions in applicationController) 112 this.store.find('eventorLocation').then(function (eventorLocations) { 113 114 eventorLocations.forEach(function (eventorLocation) { 115 116 // Create additional descriptions (if neccessary) 117 model.get('eventorLanguages').forEach(function (language) { 118 var lang = language.get('lang'); 119 120 if (eventorLocation.get('eventorLocationDescs').findBy('lang', lang) == null) { 121 var eventorLocationDesc = eventorLocation.get('eventorLocationDescs').get('firstObject'); 122 123 eventorLocation.get('eventorLocationDescs').pushObject(self.store.createRecord('eventorLocationDesc', { 124 lang: lang, 125 locTitle: '[' + lang + '] ' + eventorLocationDesc.get('locTitle'), 126 locDescription: '[' + lang + '] ' + eventorLocationDesc.get('locDescription'), 127 locStreetPlus: '[' + lang + '] ' + eventorLocationDesc.get('locStreetPlus') 128 })); 129 } 130 }); 131 132 // Get descriptions in order 133 var description = eventorLocation.get('eventorLocationDescs').findBy('lang', editLang); 134 eventorLocation.set('description', description); 135 136 }); 137 138 return eventorLocations; 139 140 }).then(function (eventorLocations) { 141 var existingArray = Array(); 142 143 model.set('templates', self.store.filter('eventorLocation', function (eventorLocation) { 144 var strCompare = eventorLocation.get('locStreet') + '|' + eventorLocation.get('locCity'); 145 var current = model.get('eventorLocation.locStreet') + '|' + model.get('eventorLocation.locCity'); 146 147 if(eventorLocation.get('id') != model.get('eventorLocation.id')) 148 { 149 if(existingArray.indexOf(strCompare) == -1 && strCompare != current) 150 { 151 existingArray.push(strCompare); 152 return true; 153 } 154 } 155 return false; 156 })); 157 158 existingArray = Array(); 159 }); 160 161 // Set vat charge types and email subscription types (TODO!) 162 model.set('vatChargeTypes', this.store.all('vatChargeType')); 163 model.set('eventorEmailSubsTypes', this.store.all('eventorEmailSub')); 164 165 // Set model 166 controller.set('model', model); 167 }, 168 setupController: function(controller, model) { 169 controller.set('model', model); 170 171 // Set breadcrumbs 172 breadcrumbTitleArray = [ 173 { title: 'Settings', target: 'eventor.edit' } 174 ]; 175 this.controllerFor('eventor').set('breadcrumbTitleArray', breadcrumbTitleArray); 176 }, 177 actions: { 178 loadTemplate: function() { 179 this.controllerFor('eventorEdit').loadTemplate(); 180 }, 181 willTransition: function(transition) { 182 var controller = this.controllerFor('eventorEdit'); 183 var model = controller.get('model'); 184 var self = this; 185 186 // Reset controller, but only if not transitioning to same route or inserting a new record 187 if (this.get('routeName') !== transition.targetName && this.get('currentModel.id') !== null) { 188 controller.reset(); 189 model.restoreState(); 190 } 191 192 if(model.get('id')) { 193 try { 194 this.store.all('eventorLocationDesc').forEach(function (eventorLocationDesc) { 195 if (eventorLocationDesc.get('id') !== null) 196 eventorLocationDesc.rollback(); 197 }); 198 this.store.all('eventorLocation').forEach(function (eventorLocation) { 199 if (eventorLocation.get('id') !== null) 200 eventorLocation.rollback(); 201 }); 202 this.store.all('eventorDesc').forEach(function (eventorDesc) { 203 if (eventorDesc.get('id') !== null) 204 eventorDesc.rollback(); 205 }); 206 } catch (e) { 207 console.log(e); 208 } 209 model.rollback(); 210 } 211 else { 212 model.unloadRecord(); 213 } 214 } 215 } 216});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.