Guest User

Untitled

a guest
Jun 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. var AddEntry = new Class({
  2. Implements: [Options, Events],
  3. options: {
  4. entry_wrap : '#entry_wrap', //comment
  5. new_entry_count : 0,
  6. create_entry_button : 'add_entry',
  7. new_entry_contents : '',
  8. entry_el_class : 'edit_entry',
  9. entry_el_wrap : 'more_entries',
  10. delete_buttons : '.delete_entry',
  11. move_up_buttons : '.move_up_entry',
  12. move_down_buttons : '.move_down_entry'
  13.  
  14.  
  15. //onEvent : $empty
  16. },
  17.  
  18. initialize: function(options) {
  19. this.setOptions(options);
  20. this.create_entry_button = $(this.options.create_entry_button);
  21. this.new_entry_count = this.options.new_entry_count
  22. this.entryElWrap = $(this.options.entry_el_wrap);
  23. },
  24.  
  25. createEntry: function(){
  26. this.create_entry_button.addEvent('click', function(e){
  27. e.preventDefault();
  28. this.new_entry_count = this.new_entry_count + 1;
  29. this.createHTML();
  30. this.injectEntry();
  31. this.initEntries();
  32. }.bind(this));
  33. },
  34.  
  35. createHTML: function(){
  36. this.new_entry = new Element('div', {
  37. 'html': this.options.new_entry_contents,
  38. 'id': 'new_entry_' + this.new_entry_count,
  39. 'class': this.options.entry_el_class
  40. });
  41. },
  42.  
  43. injectEntry: function(){
  44. this.new_entry.inject(this.entryElWrap);
  45. },
  46.  
  47. initEntries: function(){
  48. $$(this.options.delete_buttons).addEvent('click', this.deleteEntries.bind(this));
  49. /*
  50.  
  51. $$(this.options.delete_buttons).addEvent('click', deleteEntries);
  52. $$(this.options.move_up_buttons).removeEvent('click', moveEntryUp);
  53. $$(this.options.move_down_buttons).removeEvent('click', moveEntryDown);
  54. $$(this.options.move_up_buttons).addEvent('click', moveEntryUp);
  55. $$(this.options.move_down_buttons).addEvent('click', moveEntryDown);
  56. */
  57. },
  58.  
  59. deleteEntries: function(e){
  60. e.preventDefault();
  61.  
  62. firebug('delete buttons ' + this.options.delete_buttons);
  63. firebug('event ' + e.target);
  64. //this.temp_id = e.target.getParent('.' + this.options.entry_el_class).getElement('input[name=temp_chapter_id]').getProperty('value');
  65.  
  66. alert(this.temp_id);
  67.  
  68. var chapter_title = e.target.getParent('.edit_entry').getElement('input[name=title_' + temp_id + ']').getProperty('value');
  69.  
  70. var answer = confirm("Delete chapter: " + chapter_title)
  71. if (answer){
  72. e.target.getParent('.edit_entry').destroy();
  73. }
  74. }
  75. });
  76.  
  77. var Chapters = new Class({
  78. Extends: AddEntry,
  79. initialize: function(){
  80. this.parent();
  81. this.setContent();
  82. this.createEntry();
  83. },
  84.  
  85. setContent: function(){
  86. this.options.new_entry_contents = '<p><a href="#" class="move_up_entry"> </a></p><p><label>Chapter Title</label><input type="type" value="untitled ' + this.new_entry_count + '" name="title_' + this.new_entry_count +
  87. '"/></p><p><label>Chapter Description</label><textarea name="title_' + this.new_entry_count +
  88. '"></textarea></p><p><label>Upload Chapter Video File</label> <br /><input type="file" name="chapter_file_' + this.new_entry_count +
  89. '" /></p><p><a href="#" class="move_down_entry"> </a><a href="#" class="delete_entry">delete chapter</a></p><input type="hidden" name="temp_chapter_id" value="' + this.new_entry_count + '"/>'
  90. }
  91. });
  92.  
  93. AddChapter = new Chapters();
Add Comment
Please, Sign In to add comment