Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var AddEntry = new Class({
- Implements: [Options, Events],
- options: {
- entry_wrap : '#entry_wrap', //comment
- new_entry_count : 0,
- create_entry_button : 'add_entry',
- new_entry_contents : '',
- entry_el_class : 'edit_entry',
- entry_el_wrap : 'more_entries',
- delete_buttons : '.delete_entry',
- move_up_buttons : '.move_up_entry',
- move_down_buttons : '.move_down_entry'
- //onEvent : $empty
- },
- initialize: function(options) {
- this.setOptions(options);
- this.create_entry_button = $(this.options.create_entry_button);
- this.new_entry_count = this.options.new_entry_count
- this.entryElWrap = $(this.options.entry_el_wrap);
- },
- createEntry: function(){
- this.create_entry_button.addEvent('click', function(e){
- e.preventDefault();
- this.new_entry_count = this.new_entry_count + 1;
- this.createHTML();
- this.injectEntry();
- this.initEntries();
- }.bind(this));
- },
- createHTML: function(){
- this.new_entry = new Element('div', {
- 'html': this.options.new_entry_contents,
- 'id': 'new_entry_' + this.new_entry_count,
- 'class': this.options.entry_el_class
- });
- },
- injectEntry: function(){
- this.new_entry.inject(this.entryElWrap);
- },
- initEntries: function(){
- $$(this.options.delete_buttons).addEvent('click', this.deleteEntries.bind(this));
- /*
- $$(this.options.delete_buttons).addEvent('click', deleteEntries);
- $$(this.options.move_up_buttons).removeEvent('click', moveEntryUp);
- $$(this.options.move_down_buttons).removeEvent('click', moveEntryDown);
- $$(this.options.move_up_buttons).addEvent('click', moveEntryUp);
- $$(this.options.move_down_buttons).addEvent('click', moveEntryDown);
- */
- },
- deleteEntries: function(e){
- e.preventDefault();
- firebug('delete buttons ' + this.options.delete_buttons);
- firebug('event ' + e.target);
- //this.temp_id = e.target.getParent('.' + this.options.entry_el_class).getElement('input[name=temp_chapter_id]').getProperty('value');
- alert(this.temp_id);
- var chapter_title = e.target.getParent('.edit_entry').getElement('input[name=title_' + temp_id + ']').getProperty('value');
- var answer = confirm("Delete chapter: " + chapter_title)
- if (answer){
- e.target.getParent('.edit_entry').destroy();
- }
- }
- });
- var Chapters = new Class({
- Extends: AddEntry,
- initialize: function(){
- this.parent();
- this.setContent();
- this.createEntry();
- },
- setContent: function(){
- 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 +
- '"/></p><p><label>Chapter Description</label><textarea name="title_' + this.new_entry_count +
- '"></textarea></p><p><label>Upload Chapter Video File</label> <br /><input type="file" name="chapter_file_' + this.new_entry_count +
- '" /></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 + '"/>'
- }
- });
- AddChapter = new Chapters();
Add Comment
Please, Sign In to add comment