Example #1
0
 /**
  * @param \Cti\Storage\Component\Model $linkModel
  */
 public function getOppositeModel($linkModel)
 {
     foreach ($linkModel->getReferences() as $reference) {
         if ($reference->getDestination() != $this->model->getName()) {
             return $this->schema->getModel($reference->getDestination());
         }
     }
 }
Example #2
0
File: Id.php Project: cti/storage
 public function init(Model $model)
 {
     $this->name = 'id_' . $model->getName();
     $this->properties = array($this->name => new Property(array('behaviour' => $this, 'name' => $this->name, 'comment' => 'Identifier', 'type' => 'integer', 'primary' => true, 'required' => true, 'sequence' => true)));
     if (!$model->getSequence()) {
         $model->createSequence();
     }
 }
Example #3
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;
    }
Example #4
0
    public function getGeneratedCode()
    {
        $className = $this->model->getClassName();
        $name = $this->model->getName();
        $masterDataStoresConfig = $this->getMasterDataStoresConfig();
        $loadStoresCode = $this->getLoadStoresCode();
        $columnsDefinition = $this->getColumnsDefinition();
        $addHandlerCode = $this->getAddHandlerCode();
        $conditionDefinition = $this->getConditionDefinition();
        return <<<COFFEE
Ext.define 'Generated.Editor.{$className}',
  extend: 'Ext.grid.Panel'
  requires: ['Model.{$className}']
  height: 250
  initComponent: ->
    @cellEditing = new Ext.grid.plugin.CellEditing
      clicksToEdit: 1

    @plugins = [@cellEditing]

    @store =
      proxy: 'memory'
      model: 'Model.{$className}'

{$masterDataStoresConfig}
{$loadStoresCode}
    @columns = @getColumnsConfiguration()

    @tbar = [
      text: 'Добавить'
      name: 'add'
      disabled: true
      handler: =>
{$addHandlerCode}
    ,
      text: 'Удалить'
      name: 'delete'
      disabled: true
      handler: =>
        selected = @getSelection()[0]
        return unless selected
        @store.remove selected
    ]
    @callParent arguments
    @on 'selectionchange', (self, selection) =>
      (@down '[name=delete]').setDisabled !!selection.length


  initByRecord: (record) ->
    @record = record
{$conditionDefinition}
    Storage.filter '{$name}', condition, (response) =>
        @store.loadData response.data
        (@down '[name=add]').enable()

  getColumnsConfiguration: ->
{$columnsDefinition}



COFFEE;
    }
Example #5
0
File: Grid.php Project: cti/sencha
    public function getGeneratedCode()
    {
        $class = $this->model->getClassName();
        $name = $this->model->getName();
        $title = $this->model->getComment();
        $pk = $this->model->getPk();
        $idProperty = json_encode(count($pk) == 1 ? $pk[0] : $pk);
        $columns = array();
        $fields = array();
        foreach ($this->model->getProperties() as $property) {
            $fields[] = array('name' => $property->getName(), 'type' => $property->getJavascriptType());
            $item = array('dataIndex' => $property->getName(), 'header' => $property->getComment());
            $columns[] = $item;
            if (!$property->getBehaviour()) {
                $width = 80;
                if ($property->getJavascriptType() == 'string') {
                    $width = 120;
                }
            }
        }
        $fields = json_encode($fields);
        $columns = json_encode($columns);
        $configuration = $this->getColumnConfiguration();
        $additionalStoresPreConstructor = $this->getAdditionalStoresPreConstructor();
        $additionalStoresAfterConstructor = $this->getAdditionalStoresAfterConstructor();
        return <<<COFFEE
Ext.define 'Generated.Grid.{$class}',

  extend: 'Ext.grid.Panel'

  title: '{$title}'

  token: '/{$name}/'

  store: model: 'Model.{$class}'
  getAvailableColumns: -> {$columns}
  getColumnConfiguration: -> {$configuration}

  requires: ['Model.{$class}', 'Form.{$class}']

  getTopToolbar: -> [
    xtype:'textfield'
    emptyText:'Фильтр'
    width:220
    enableKeyEvents: true
    listeners: keyup: 
      buffer: 50
      fn: => @applyFilter()
  ,
    text:'Add'
    handler: => @onAddClick()
    '-'
    text:'Edit'
    disabled: true
    handler: => @onEditClick()
    '-'
    text:'Remove'
    disabled: true
    handler: => @onRemoveClick()
  ]

  applyFilter: -> 
    value = Ext.util.Format.lowercase @down('[xtype=textfield]').getValue()
    @store.clearFilter()
    if value
      @store.filterBy (r) -> 
        found = false
        for k, v of r.data
          found = found || Ext.util.Format.lowercase(v).indexOf(value) != -1
        found

  getSelected: -> @getSelectionModel().getSelection()[0]

  onSelectionChange: ->
    disabled = !@getSelectionModel().getSelection().length
    @down('[text=Edit]').setDisabled disabled
    @down('[text=Remove]').setDisabled disabled

  onAddClick: -> Ext.create 'Window.{$class}', grid: @
  onRemoveClick: -> Storage.remove '{$name}', @getSelected().getPk(), => @getSelected().store.remove @getSelected()
  onItemClick: ->
  onItemDblClick: -> @onEditClick()
  onEditClick: -> Ext.create 'Window.{$class}', Ext.apply @getSelected().getPk(), grid: @

  loadData: -> Storage.getList '{$name}', (response) => @store.loadData response.data
  
  initComponent: ->
{$additionalStoresPreConstructor}
    configuration = @getColumnConfiguration()
    @columns = []
    Ext.Array.each @getAvailableColumns(), (column) =>
      if configuration[column.dataIndex]
        @columns.push Ext.apply column, configuration[column.dataIndex]

    @tbar = @getTopToolbar()
    @callParent arguments
{$additionalStoresAfterConstructor}

    @on 'selectionchange', => @onSelectionChange()
    @on 'itemclick', => @onItemClick()
    @on 'itemdblclick', => @onItemDblClick()
    @on 'afterrender', =>
        @loadData()
    , single: true

COFFEE;
    }