/*
 * AddFolderModal.js
 * 
 * Copyright (c) 2011, OSBI Ltd. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */
/**
 * The "add a folder" dialog
 */
var AddFolderModal = Modal.extend({

    type: "save",
    closeText: "Save",

    events: {
        'click .form_button': 'save',
        'submit form': 'save'
    },

    buttons: [
        { text: "OK", method: "save" }
    ],

    initialize: function(args) {
        var self = this;
        this.success = args.success;
        this.path = args.path;
        this.message = "<form id='add_folder'>" +
            "<label for='name'>To add a new forlder, " + 
            "please type a name in the text box below:</label><br />" +
            "<input type='text' name='name'" +
            "</form>"

        _.extend(this.options, {
            title: "Add Folder"
        });
    },
    
    type: "save",

    save: function( event ) {
        event.preventDefault( );
        var self = this;
        
        var name = $(this.el).find('input[name="name"]').val();
        var file = this.path + name;
        (new SavedQuery( { file: file , name: name} ) ).save( { 
            success: self.success,
            dataType: "text",
            error: this.error
        } );
        this.close();
        return false;
    },

    error: function() {
        $(this.el).find('dialog_body')
            .html("Could not add new folder");
    }


});

/*
 * AddFolderModal.js
 * 
 * Copyright (c) 2011, OSBI Ltd. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */
/**
 * The "add a folder" dialog
 */
var AddFolderModal = Modal.extend({

    type: "save",
    closeText: "Save",

    events: {
        'click .form_button': 'save',
        'submit form': 'save'
    },

    buttons: [
        { text: "OK", method: "save" }
    ],

    initialize: function(args) {
        var self = this;
        this.success = args.success;
        this.path = args.path;
        this.message = "<form id='add_folder'>" +
            "<label for='name'>To add a new folder, " + 
            "please type a name in the text box below:</label><br />" +
            "<input type='text' name='name'" +
            "</form>"

        _.extend(this.options, {
            title: "Add Folder"
        });
    },
    
    type: "save",

    save: function( event ) {
        event.preventDefault( );
        var self = this;
        
        var name = $(this.el).find('input[name="name"]').val();
        var file = this.path + name;
        (new SavedQuery( { file: file , name: name} ) ).save( { 
            success: self.success,
            dataType: "text",
            error: this.error
        } );
        this.close();
        return false;
    },

    error: function() {
        $(this.el).find('dialog_body')
            .html("Could not add new folder");
    }


});

fix #239 - fix typo in new folder dialog