Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. (function(app){
  2. app.Views.MainView = Backbone.View.extend({
  3. el:'html',
  4. events:{
  5. 'click .clickAddPupil':'showFormPupil',
  6. 'click .addFormPupil':'addPupil',
  7. 'change input':'validate'
  8. },
  9. initialize:function(){
  10. this.listenTo(this.collection, 'add', this.render);
  11. },
  12. render:function(){
  13. var PupilView = new app.Views.PupilView({
  14. model:this.model
  15. });
  16. this.$('ul').append(PupilView.render().el);
  17. },
  18. showFormPupil:function(){
  19. $('form').removeClass();
  20. },
  21. validate:function(elem){
  22. if(elem.val()==0){
  23. console.log('vcdv')
  24. }
  25.  
  26. },
  27. addPupil:function() {
  28. this.$('form').submit(function(){return false});
  29. var dataObject = {
  30. name: this.$('.name').val(),
  31. surname: this.$('.surname').val(),
  32. mathematics: this.$('.mathematics').val(),
  33. english: this.$('.english').val(),
  34. ukrainian: this.$('.ukrainian').val(),
  35. history: this.$('.history').val()
  36. };
  37. this.model = new app.Models.PupilModel();
  38. this.model.set(dataObject);
  39. this.collection.add(this.model);
  40. this.$('form').addClass('none');
  41. },
  42. })
  43. }(window.application));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement