/** * Generates grid columns object * * @param \Engine\Crud\Grid\Extjs $grid * @return string */ public static function _(Grid $grid) { $code = "\n columnsGet: function(){\n return ["; $columns = []; foreach ($grid->getColumns() as $column) { if ($column instanceof Column) { $type = $column->getType(); /*if (!method_exists(__CLASS__, '_'.$type)) { throw new \Engine\Exception("Field with type '".$type."' haven't render method in '".__CLASS__."'"); }*/ switch ($type) { case 'image': $columnCode = forward_static_call(['static', '_' . $type], $column); break; case 'check': $columnCode = forward_static_call(['static', '_' . $type], $column); break; default: $columnCode = forward_static_call(['static', '_column'], $column); break; } $columns[] = $columnCode; } } $code .= implode(",", $columns); $code .= "\n ]\n },\n "; return $code; }
/** * Generates grid paginate object * * @param \Engine\Crud\Grid\Extjs $grid * @return string */ public static function _(Grid $grid) { $action = $grid->getAction(); $sortParams = $grid->getSortParams(); if ($sortParams) { foreach ($sortParams as $param => $value) { $action = self::setUrlParam($action, $param, $value); } } $code = "\n getBottomToolbarItems: function() {\n var me = this;\n\n var items = [\n me.getPagingToolbar()\n ];\n\n return items;\n },"; return $code; }
/** * Generates grid component object * * @param \Engine\Crud\Grid\Extjs $grid * @return string */ public static function _(Grid $grid) { $buildStore = $grid->isBuildStore(); $code = "\n buildStore: " . ($buildStore ? 'true' : 'false') . ",\n\n initComponent: function() {\n var me = this;\n\n if (me.buildStore) {\n Ext.apply(me, {\n store : me.createStore(me.store)\n });\n }\n\n "; $editType = $grid->getEditingType(); if ($editType) { $code .= "me.cellEditing = Ext.create('Ext.grid.plugin." . ucfirst($editType) . "Editing', {\n clicksToEdit: 2,\n listeners: {\n scope: me,\n edit: me.onEdit\n }\n });\n me.plugins = me.cellEditing;"; } $code .= "\n me.columns = me.columnsGet();\n me.tbar = me.getTopToolbarItems();\n me.bbar = me.getBottomToolbarItems();\n\n me.callParent(arguments);\n },\n\n "; /* me.on('selectionchange', me.onSelect, this); me.on('celldblclick', me.onDbClick, this); me.on('cellclick', me.onClick, this); me.on('keypress', me.onKeyPress, this); },"; */ return $code; }
/** * Generates a widget to show a html grid * * @param \Engine\Crud\Grid\Extjs $grid * @return string */ public static function _(Grid $grid) { $title = $grid->getTitle(); $code = "\n Ext.define('" . static::getGridName() . "', {\n extend: 'Ext.ux.crud.Grid',\n store: '" . static::getStoreName() . "',\n alias: 'widget." . static::$_module . ucfirst(static::$_prefix) . "Grid',\n "; $width = $grid->getWidth(); if ($width) { $code .= "width: " . $width . ",\n "; } $height = $grid->getHeight(); if ($width) { $code .= "height: " . $height . ",\n "; } $editType = $grid->getEditingType(); if ($editType) { static::addRequires("Ext.grid.plugin." . ucfirst($editType) . "Editing"); } static::addRequires("Ext.form.field.*"); static::addRequires("Ext.ux.crud.Grid"); $code .= "itemId: '" . static::$_module . ucfirst(static::$_prefix) . "Grid',"; return $code; }
/** * Generates a widget to show a html grid * * @param \Engine\Crud\Grid\Extjs $grid * @return string */ public static function _(Grid $grid) { $title = $grid->getTitle(); $prefix = ucfirst(static::$_prefix); $code = "\n Ext.define('" . static::getControllerName() . "', {\n extend: 'Ext.app.Controller',\n title: '" . $title . "',\n baseParams: {},\n "; $code .= "requires: ["; $code .= "'" . static::getStoreLocalName() . "',"; $code .= "'" . static::getStoreName() . "',"; $code .= "'" . static::getGridName() . "',"; $code .= "'" . static::getFilterName() . "'"; if ($grid->isEditable()) { $code .= ",'" . static::getFormName() . "'"; } $code .= "],\n "; $additionals = []; if ($grid->isEditable()) { $additionals[] = "\n {\n type: 'form',\n controller: '" . static::getControllerName() . "'\n }"; } foreach ($grid->getAdditionals() as $addional) { $additionals[] = "\n {\n type: '" . $addional['type'] . "',\n controller: '" . ucfirst($addional['module']) . '.controller.' . ucfirst($addional['key']) . "',\n param: '" . $addional['param'] . "'\n }"; } $code .= "\n additionals: [" . implode(",", $additionals) . "\n ],\n "; $code .= "\n init: function() {\n var me = this;\n\n me.storeLocal = this.getStore('" . static::getStoreLocalName() . "');\n me.store = this.getStore('" . static::getStoreName() . "');\n me.grid = this.getView('" . static::getGridName() . "');\n "; if ($grid->isEditable()) { $code .= "me.form = this.getView('" . static::getFormName() . "');\n "; } $code .= "me.filter = this.getView('" . static::getFilterName() . "');\n me.store.addBaseParams(me.baseParams);\n /*me.storeLocal.addListener('load', function(){\n me._onPingSuccess();\n }, me);\n me.storeLocal.load();*/\n me.store.load();\n me.activeStore = me.store;\n },\n\n _onPingSuccess: function() {\n var me = this;\n\n localCnt = me.storeLocal.getCount();\n\n if (localCnt > 0){\n for (i = 0; i < localCnt; i++){\n var localRecord = me.storeLocal.getAt(i);\n var deletedId = localRecord.data.id;\n delete localRecord.data.id;\n store.add(localRecord.data);\n localRecord.data.id = deletedId;\n }\n me.store.sync();\n for (i = 0; i < localCnt; i++){\n me.localStore.removeAt(0);\n }\n }\n\n me.store.load();\n me.activeStore = this.store;\n },\n\n _onPingFailure: function() {\n var me = this;\n\n me.activeStore = me.storeLocal;\n }\n\n });\n "; return $code; }
/** * Generates a widget to show a html grid * * @param \Engine\Crud\Grid\Extjs $grid * @return string */ public static function _(Grid $grid) { $code = "\n Ext.define('" . static::getModelName() . "', {\n extend: 'Ext.data.Model',"; $columns = []; $validations = []; $primary = false; foreach ($grid->getColumns() as $column) { if ($column instanceof Column) { $type = $column->getType(); if (!method_exists(__CLASS__, '_' . $type)) { throw new \Engine\Exception("Field with type '" . $type . "' haven't render method in '" . __CLASS__ . "'"); } $columnCode = forward_static_call(['self', '_' . $type], $column); //$validationCode = "{field: '".$field."', type: }"; /* * type: presence length inclusion exclusion format */ $columns[] = $columnCode; //$validations[] = $validationCode; if ($column instanceof Column\Primary) { $primary = $column->getKey(); } } } $code .= "\n fields: [" . implode(",", $columns) . "\n ],"; $code .= "\n validations: [" . implode(",", $validations) . "]"; if ($primary !== false) { $code .= ",\n idProperty: '" . $primary . "'"; } $code .= "\n });"; return $code; }
/** * Generates grid functions object * * @param \Engine\Crud\Grid\Extjs $grid * @return string */ public static function _(Grid $grid) { $title = $grid->getTitle(); $code = "\n Ext.define('" . static::getWinName() . "', {\n extend: 'Ext.Window',\n itemId: '" . static::$_module . ucfirst(static::$_prefix) . "Window',\n layout: 'fit',\n items: [\n { xtype: '" . static::$_module . ucfirst(static::$_prefix) . "Grid', itemId: '" . static::$_module . ucfirst(static::$_prefix) . "Grid' }\n ]\n });"; return $code; }
/** * Init helper * * @param \Engine\Crud\Grid\Extjs|\Engine\Crud\Form\Extjs $element * @return string */ public static function init($element) { static::$_module = \Phalcon\Text::camelize($element->getModuleName()); static::$_prefix = \Phalcon\Text::camelize($element->getKey()); }