Example #1
0
 public function getCode()
 {
     $fields = array();
     foreach ($this->model->getProperties() as $property) {
         $fields[] = $property->getName();
     }
     $code = $this->fenom->render('repository', array('model' => $this->model, 'fields' => $fields, 'schema' => $this->schema));
     return $code;
 }
Example #2
0
 protected function modelAsArray(Model $model)
 {
     $result = array('pk' => $model->getPk(), 'has_log' => (bool) $model->getBehaviour('log'), 'is_link' => (bool) $model->getBehaviour('link'), 'properties' => array(), 'references' => array());
     foreach ($model->getProperties() as $property) {
         $result['properties'][$property->getName()] = $this->propertyAsArray($property);
     }
     foreach ($model->getOutReferences() as $reference) {
         $result['references'][] = $this->referenceAsArray($reference);
     }
     return $result;
 }
Example #3
0
File: Grid.php Project: cti/sencha
 protected function getColumnConfiguration()
 {
     $configuration = array();
     /**
      * @var \Cti\Storage\Component\Reference[] $referenceByColumns
      */
     $referencesByColumns = array();
     foreach ($this->model->getOutReferences() as $reference) {
         if (count($reference->getProperties()) == 1) {
             $properties = $reference->getProperties();
             $property = array_shift($properties);
             $referencesByColumns[$property->getName()] = $reference;
         }
     }
     foreach ($this->model->getProperties() as $property) {
         if (!$property->getBehaviour()) {
             $width = 80;
             if ($property->getJavascriptType() == 'string') {
                 $width = 120;
             }
             $configuration[$property->getName()] = array('width' => $width);
         }
         // Need to add renderer, this column in reference
         if (isset($referencesByColumns[$property->getName()])) {
             $reference = $referencesByColumns[$property->getName()];
             if (empty($configuration[$property->getName()])) {
                 $configuration[$property->getName()] = array();
             }
             $configuration[$property->getName()]['width'] = 120;
             $configuration[$property->getName()]['renderer'] = " (v) =>\r\n          record = @additionalStores.{$reference->getDestination()}.findRecord 'id_{$reference->getDestination()}', v\r\n          \"#{v} #{record.data.name}\" or \"\"\n";
         }
     }
     $code = "";
     foreach ($configuration as $columnName => $config) {
         $code .= "    {$columnName}:\n";
         foreach ($config as $k => $v) {
             $code .= "      {$k}:" . (is_numeric($v) || $k == 'renderer' ? $v : '"' . $v . '"') . "\n";
         }
     }
     return "\n" . $code;
 }
Example #4
0
 public function getColumnsDefinition()
 {
     /**
      * When we create editor in window, we need to disable some of column editors
      */
     $removeColumnsEditorFillCode = array();
     foreach ($this->model->getOutReferences() as $reference) {
         $model = $this->schema->getModel($reference->getDestination());
         $removeColumnsEditorFillCode[] = "if owner instanceof Window." . $model->getClassName() . "\r\n      removeColumnsEditor.push 'id_" . $model->getName() . "'\r\n";
     }
     $removeColumnsEditorFillCode = implode("    else ", $removeColumnsEditorFillCode);
     $createdColumns = array();
     $columnsCode = array();
     foreach ($this->model->getOutReferences() as $reference) {
         $model = $this->schema->getModel($reference->getDestination());
         $name = $model->getName();
         $properties = $reference->getProperties();
         $property = array_shift($properties);
         $createdColumns[] = 'id_' . $name;
         $columnsCode[] = "      header: '" . $model->getComment() . "'\r\n      dataIndex: '" . $property->getName() . "'\r\n      flex: 2\r\n      editor: new Ext.form.field.ComboBox\r\n        store: @masterDataStores.{$name}\r\n        valueField: '" . $property->getName() . "'\r\n        displayField: 'name'\r\n        queryMode: 'local'\r\n      renderer: (v) =>\r\n        record = @masterDataStores.{$name}.findRecord 'id_{$name}', v\r\n        if record then record.data.name else ''";
     }
     foreach ($this->model->getProperties() as $property) {
         if ($property->getBehaviour('log')) {
             continue;
         }
         $xtype = 'textfield';
         switch ($property->getType()) {
             case 'integer':
                 $xtype = 'numberfield';
                 break;
         }
         if (!in_array($property->getName(), $createdColumns)) {
             $columnsCode[] = "\r\n      header: '" . $property->getComment() . "'\r\n      flex: 1\r\n      dataIndex: '" . $property->getName() . "'\r\n      editor:\r\n        xtype: '{$xtype}'\r\n        allowBlank: " . ($property->getRequired() ? "false" : "true") . "\r\n                ";
         }
     }
     $code = "    columns = [\n" . implode("\n    ,\n", $columnsCode) . "\r\n    ]\r\n\r\n    owner = @parentWindow\r\n    removeColumnsEditor = []\r\n    {$removeColumnsEditorFillCode}\r\n    for column in columns\r\n        delete column.editor if Ext.Array.indexOf(removeColumnsEditor, column.dataIndex) isnt -1\r\n    columns\r\n\r\n";
     return $code;
 }
Example #5
0
File: Form.php Project: cti/sencha
    public function getGeneratedCode()
    {
        $class = $this->model->getClassName();
        $name = $this->model->getName();
        $pk = $this->model->getPk();
        $idProperty = json_encode(count($pk) == 1 ? $pk[0] : $pk);
        $items = array();
        // @todo References only by 1 field
        /**
         * @var \Cti\Storage\Component\Reference[] $referenceByField
         */
        $referenceByField = array();
        foreach ($this->model->getOutReferences() as $reference) {
            if (count($reference->getProperties()) == 1) {
                $properties = $reference->getProperties();
                $property = array_shift($properties);
                $referenceByField[$property->getName()] = $reference;
            }
        }
        $item_list = $behaviours = array();
        foreach ($this->model->getProperties() as $property) {
            $reference = isset($referenceByField[$property->getName()]) ? $referenceByField[$property->getName()] : null;
            $item = array('name' => $property->getName(), 'allowBlank' => !!$property->getRequired(), 'fieldLabel' => $property->getComment());
            if ($reference) {
                $item['xtype'] = 'ctipicker';
                $item['model'] = $reference->getDestination();
                $item['displayField'] = 'name';
                $item['valueField'] = 'id_' . $reference->getDestination();
            } else {
                switch ($property->getJavascriptType()) {
                    case 'date':
                        $item['xtype'] = 'datefield';
                        break;
                    case 'numeric':
                        $item['xtype'] = 'numberfield';
                        break;
                    default:
                        $item['xtype'] = 'textfield';
                        break;
                }
            }
            if ($property->getBehaviour()) {
                $item['readOnly'] = true;
                $item['disabled'] = true;
                if (!in_array($property->getName(), $pk)) {
                    $behaviours[] = $property->getName();
                }
            } else {
                $item_list[] = $property->getName();
            }
            if ($property->getJavascriptType() == 'numeric') {
                $item['xtype'] = 'numberfield';
            }
            $items[$property->getName()] = $item;
        }
        $item_list = json_encode(array_merge($item_list, $pk, $behaviours));
        $items = json_encode($items);
        $pk_getter = array();
        foreach ($pk as $key) {
            $pk_getter[] = $key . ": @" . $key;
        }
        $pk_getter = implode(', ', $pk_getter);
        return <<<COFFEE
Ext.define 'Generated.Form.{$class}',

  requires: ['Cti.Picker'],
  extend: 'Ext.form.Panel'
  bodyPadding: 10
  monitorValid: true
  border: false

  getPk: -> {$pk_getter}

  getItemsConfig: -> {$items}
  getItemsList: -> {$item_list}

  modelExists: -> !Ext.Array.contains(Ext.Object.getValues(@getPk()), undefined)

  initComponent: ->
    @items = []
    config = @getItemsConfig()
    for item in @getItemsList()
      @items.push config[item]

    @callParent arguments

    if @modelExists()
      Storage.getModel '{$name}', @getPk(), (response) =>
        model = Ext.create 'Model.{$class}', response.data
        @getForm().loadRecord model
        @fireEvent 'recordloaded', model
COFFEE;
    }