Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * 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;
 }