Ext.define("Ext.ux.folderorganizer.PagingToolbar", {
	extend: "Ext.toolbar.Paging",
	initComponent: function() {
		var me = this;

		me.callParent(arguments);

		// Hack to prevent the number field in pagination from
		// showing up as dirty in serialization contexts
		var i_inputItem = me.down("#inputItem");

		if (i_inputItem) {
			i_inputItem.isFormField = false;
		}

		return me;
	},
	getPagingItems: function() {
		var me = this;

		var items = me.callParent();

		if (Ext.isArray(me.extraButtons)) {
			Ext.Array.each(me.extraButtons, function(button) {
				switch (button) {
					case "add":
						items.push(
              Ext.create("Ext.button.Button", {
	text: me.getI18N("add"),
	tooltip: me.getI18N("addTips").toString(),
	iconCls: "ip2-icon-add",
	handler: function() {
		me.ownerCt.addRow();
	}
              })
            );
						break;
					case "remove":
						items.push(
              Ext.create("Ext.button.Button", {
	text: me.getI18N("remove"),
	tooltip: me.getI18N("removeTips").toString(),
	iconCls: "ip2-icon-remove",
	handler: function() {
		me.ownerCt.removeRow();
	}
              })
            );
						break;
					case "refresh":
						items.push(
              Ext.create("Ext.button.Button", {
	text: me.getI18N("refresh"),
	tooltip: me.getI18N("refreshTips").toString(),
	iconCls: "ip2-icon-refresh",
	handler: function() {
		me.ownerCt.refresh();
	}
              })
            );
						break;
				}
			});
		}

		if (me.displayFilterField) {
			me.filterField = Ext.create("Ext.form.field.Text", {
				width: 300,
				enableKeyEvents: true,
				name: me.namePrefix + ".filterField",
				isFormField: false,
				listeners: {
					scope: me,
					keydown: function(fld, e) {
						me.onPagingKeyDown(fld, e);
						me.child("#inputItem").setValue(1);
						if (e.getKey() == e.ENTER) {
							me.ownerCt.store.load({
								params: {
									start: 0
								}
							});
						}
					},
					blur: me.onPagingBlur
				}
			});
			items.push(me.filterField);
		}

		return items;
	},
	getI18N: function(key) {
		return (ip2.folderorganizer) ? ip2.folderorganizer.getTextValue(key) : key;
	}
});
