wejsv2old-plugin-cdp-profile
Version:
We.js plugin wejsv2old-plugin-cdp-profile
103 lines (90 loc) • 2.73 kB
JavaScript
App.WeCoursesComponent = Ember.Component.extend(App.StudiesWorkMixin, {
promptText: 'Tipo de Curso',
courseTypes: ['Técnico', 'Graduação', 'Pós-Graduação'],
classNames: ['we-courses'],
birthday: Ember.computed.alias('origContext.model.birthDate'),
// courses: [],
init: function () {
// body...
var self = this;
self._super.apply(self, arguments);
self.set('url', we.configs.server.providers.accounts + '/course');
Ember.$.get(self.get('url') + '?user=' + self.get('user'))
.then(function (data){
self.set('courses', data.course);
}, function (error){
console.log('erro: ', error);
self.set('courses', []);
})
},
actions: {
addCourse: function (){
var self = this;
$.blockUI({ css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}, message: 'Adicionando Curso...' });
// Set the object to send to server
var course = {
type: self.get('type'),
name: self.get('name'),
school: self.get('school'),
endyear: self.get('endyear'),
user: self.get('user')
}
Ember.$.post(self.get('url'),course)
.then(function (crs){
$.unblockUI();
self.resetInputState();
self.get('courses').pushObject(crs.course);
}, function (error){
$.unblockUI();
console.log('error', error);
})
},
removeCourse: function (id){
var self = this;
$.blockUI({ css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}, message: 'Removendo Curso...' });
// Set the object to send to server
Ember.$.ajax({
url: self.get('url') + '/' + id,
method: 'DELETE',
dataType: 'json'
})
.then(function (resp){
self.get('courses').forEach(function (course){
if (course.id == resp.course.id) return self.get('courses').removeObject(course);
});
$.unblockUI();
}, function (error){
$.unblockUI();
console.log('erro::', error);
})
},
showModal: function (id){
this.set('WeSmallModal.id', id);
this.get('WeSmallModal').show();
},
},
resetInputState: function (){
this.setProperties({
type: null,
name: null,
school: null,
endyear: null
})
},
});