// Copyright (c) 2000-2008 Synology Inc. All rights reserved.
MODULE_RECENT_ARTICLE = function(div_id, config) {
	MODULE_RECENT_ARTICLE.superclass.constructor.call(this, div_id, config);

	var column_central = SYNOBLOG_COLUMN_CENTRAL.instance();
	column_central.on('article_update', this.init, this);
};

Ext.extend(MODULE_RECENT_ARTICLE, SYNOBLOG_MODULE, {
	init: function() {
		var el_content = Ext.get(this.div_id+'_content');
		if(el_content != null) {
			var mgr_content = el_content.getUpdateManager();
			mgr_content.update("modules/recent_article.php", "action=get_module_content");
		}
	},
	customizeConfigDialog: function() {
		this.configDialog.addButton(blog_str_common_save, this.save, this);
		this.configDialog.addButton(blog_str_common_close, this.hide, this);

		var layout = this.configDialog.getLayout();
		layout.beginUpdate();
		
		var content = '<div style="margin:20px;width:340px;" id="recent_article_form"></div>';

		var cp = layout.add('center', new Ext.ContentPanel(Ext.id(), {autoCreate:true, title: blog_str_recent_article_title, background:true}));
		cp.setContent(content);
		layout.endUpdate();

		this.configDialog.getLayout().getRegion("center").showPanel(0);

		this.configDialog.on('show', function(dialog){
			this.form.load({url: "modules/recent_article.php", params: 'action=get_article_num'});
		}, this);

		this.getForm();
	},
	getConfigDialogData: function(action) {
		if(action.type == 'submit') {
			this.configDialog.hide();
		}
	},
	getForm: function() {
		var ds = new Ext.data.SimpleStore({
			fields: ['num'],
			data : [[1], [2], [3], [5], [7], [10], [15], [20]]
		});

		this.form.column({labelWidth: 200, width:320},
			new Ext.form.ComboBox({
				fieldLabel: blog_str_recent_article_num,
				name: 'num',
				store: ds,
				displayField:'num',
				typeAhead: true,
				mode: 'local',
				triggerAction: 'all',
				selectOnFocus:true,
				width: 100,
				editable: false
			})
		);
		this.form.render('recent_article_form');
	},
	save: function() {
		this.form.submit({url:'modules/recent_article.php',
			waitTitle:' ',
			waitMsg:blog_str_man_blog_header_pic_plz_wait,
			params: {action: 'save_article_num'}
		});
	}
});

SYNOBLOG.instance().registerModule("recent_article", {hasConfigDialog: 1, width:400, height:200}, MODULE_RECENT_ARTICLE);
