Ext.define("Ext.ux.navigation.view.RolePermissionGrid", {


	extend: "Ext.grid.Panel",
	alias: [
		"widget.rolepermissiongrid"
	],

	controller: "navigation.rolepermissiongrid",

	options: null,

	initComponent: function() {

		var i_self = this;
		var controller = i_self.getController();
		var s_modelName = "rolepermissionrows";
		var a_fields = [];

		var i_store;

		if (!i_self.fields) {

			a_fields = [
				{
					name: "id",
					type: "auto"
				},
				{
					name: "description",
					type: "string"
				}
			];
		}
		else {
			a_fields = i_self.fields;
		}
		if (!i_self.store) {

			if (!Ext.ClassManager.isCreated(s_modelName)) {

				var s_idProperty = "id";

				Ext.Array.each(a_fields, function(i_field) {
					if (i_field.identifier) {
						s_idProperty = i_field.name;
						return false;
					}
				});

				Ext.define(s_modelName, {
					extend: "Ext.data.Model",
					fields: a_fields,
					idProperty: s_idProperty,
					proxy: {
						type: "pagingmemory",
						reader: {
							type: "json",
							rootProperty: "rows",
							totalProperty: "total"
						}
					},
					pageSize: 50
				});
			}

			i_store = Ext.create("Ext.data.Store", {
				model: s_modelName,
				pageSize: 50
			});

			i_self.store = i_store;
		}

		if (!i_self.columns) {
			i_self.columns = [
				{ text: ip2.i18n({ da: "Id", en: "Id" }), dataIndex: "id", flex: 1 },
				{ text: ip2.i18n({ da: "Beskrivelse", en: "Description" }), dataIndex: "description", flex: 3 }
			];
		}

		i_self.callParent();

		i_store = i_self.getStore();

		i_store.on({
			datachanged: {
				fn: function(store, a_records) {

					if (!i_self.isDestroyed) {

						var i_widget = i_self.up("ip2widget");

						if (i_widget) {

							var i_widgetCmp = i_widget.getWidgetCmp();

							if (i_widgetCmp) {
								i_widget.fireEvent("dirtychange", i_widget, i_widgetCmp.isDirty());
							}
						}
					}
				}
			},
			reset: {
				fn: function(i_store) {

					var i_widget = i_self.up("ip2widget");

					if (i_widget) {

						var i_widgetCmp = i_widget.getWidgetCmp();

						if (i_widgetCmp) {
							i_widgetCmp.resetDirty();
						}
					}
				}
			}
		});
	}
});
