
function regal_brochures(app) {
	this.app = app;
}

regal_brochures.prototype.seasonBrochures = function(parent, season_id, brochure_id) {
    var win = new Window(this.app, 'regal_brochures_seasonBrochures_' + brochure_id);
    win.data = {
        season_id: season_id,
        brochure_id: brochure_id
    };
    var doc = new JSON.Document('packet', JSON.DefaultPacket('regal_brochures','getBrochure'));
    doc.packet.xmldata = {brochure_id: brochure_id};
    win.loadContent({regal_seasons_seasonBrochures:'regal_brochures/seasonBrochures.js'}, doc, null);
}

regal_brochures.prototype.editComment = function(parent, record, save) {
    var win = new Window(this.app, 'regal_brochures_editComment_' + parent.data.brochure_id + '_' + record.data.id);
    win.data = {
        parent: parent,
        record: record,
		save: save
    };
    win.loadContent({regal_seasons_editComment:'regal_brochures/editComment.js'}, null, null);
}

regal_brochures.prototype.seasonBrochuresList = function(parent) {
    var win = new Window(this.app, 'regal_brochures_seasonBrochuresList');
    var doc = new JSON.Document('packet', JSON.DefaultPacket('regal_brochures','listSeasonsByYear'));
    win.loadContent({regal_seasons_seasonBrochuresList:'regal_brochures/seasonBrochuresList.js'}, doc, null);
}

regal_brochures.prototype.create = function(parent, season_id) {
    var win = new Window(this.app, 'regal_brochures_create_brochure_' + random());
    win.data = {
        parent: parent,
        season_id: season_id
    };
    win.loadContent({regal_brochures_create:'regal_brochures/create.js'}, null, null);
}

regal_brochures.prototype.saveCopy = function(brochure_id, season_id, products) {

    var win = new Window(this.app, 'regal_brochures_saveCopy_' + random());
    win.data = {
    	brochure_id: brochure_id,
        season_id: season_id,
        products: products
    };
    win.loadContent({regal_brochures_saveCopy:'regal_brochures/saveCopy.js'}, null, null);
}

regal_brochures.prototype.rename = function(record) {
    var win = new Window(this.app, 'regal_brochures_rename_brochure_' + record.data.id);
    win.data = {
        record: record
    };
    win.loadContent({regal_brochures_rename:'regal_brochures/rename.js'}, null, null);
}

regal_brochures.prototype.printBrochure = function(template_name, brochure_id, columns, data, write_perm, callback) {
    var win = new Window(this.app, 'regal_brochures_print_' + random());
    win.data = {
        data: data,
        template_name: template_name,
        brochure_id: brochure_id,
        columns: columns,
        callback: callback,
        write_perm: write_perm
    };
    var tpl = {};
    tpl['regal_brochures_print_' + template_name] = 'regal_brochures/printTpl_' + template_name + '.js'
    win.loadContent(tpl, null, null);
}


