Esempio n. 1
0
 public function prepareTable()
 {
     $fromCode = post('locale_from', null);
     $toCode = post('locale_to', Locale::getDefault()->code);
     $this->hideTranslated = post('hide_translated', false);
     /*
      * Page vars
      */
     $this->vars['hideTranslated'] = $this->hideTranslated;
     $this->vars['defaultLocale'] = Locale::getDefault();
     $this->vars['locales'] = Locale::all();
     $this->vars['selectedFrom'] = $selectedFrom = Locale::findByCode($fromCode);
     $this->vars['selectedTo'] = $selectedTo = Locale::findByCode($toCode);
     /*
      * Make table config, make default column read only
      */
     $config = $this->makeConfig('config_table.yaml');
     if (!$selectedFrom) {
         $config->columns['from']['readOnly'] = true;
     }
     if (!$selectedTo) {
         $config->columns['to']['readOnly'] = true;
     }
     /*
      * Make table widget
      */
     $widget = $this->makeWidget('Backend\\Widgets\\Table', $config);
     $widget->bindToController();
     /*
      * Populate data
      */
     $dataSource = $widget->getDataSource();
     $dataSource->bindEvent('data.getRecords', function ($offset, $count) use($selectedFrom, $selectedTo) {
         $messages = $count ? Message::orderBy('message_data', 'asc')->limit($count)->offset($offset)->get() : Message::orderBy('message_data', 'asc')->get();
         $result = $this->processTableData($messages, $selectedFrom, $selectedTo);
         return $result;
     });
     $dataSource->bindEvent('data.getCount', function () {
         return Message::count();
     });
     $dataSource->bindEvent('data.updateRecord', function ($key, $data) {
         $message = Message::find($key);
         $this->updateTableData($message, $data);
         CacheHelper::clear();
     });
     $dataSource->bindEvent('data.deleteRecord', function ($key) {
         if ($message = Message::find($key)) {
             $message->delete();
         }
     });
     $this->vars['table'] = $widget;
 }
Esempio n. 2
0
 public function prepareGrid()
 {
     $fromCode = post('locale_from', null);
     $toCode = post('locale_to', Locale::getDefault()->code);
     /*
      * Page vars
      */
     $this->vars['hideTranslated'] = post('hide_translated', false);
     $this->vars['defaultLocale'] = Locale::getDefault();
     $this->vars['locales'] = Locale::all();
     $this->vars['selectedFrom'] = $selectedFrom = Locale::findByCode($fromCode);
     $this->vars['selectedTo'] = $selectedTo = Locale::findByCode($toCode);
     /*
      * Make grid config, make default column read only
      */
     $config = $this->makeConfig('config_grid.yaml');
     $config->data = $this->getGridData($selectedFrom, $selectedTo);
     if (!$selectedFrom) {
         $config->columns['from']['readOnly'] = true;
     }
     if (!$selectedTo) {
         $config->columns['to']['readOnly'] = true;
     }
     /*
      * Make grid widget
      */
     $widget = new Grid($this, $config);
     $widget->bindEvent('grid.dataChanged', function ($action, $changes) {
         if ($action == 'remove') {
             $this->removeGridData($changes);
         } else {
             $this->updateGridData($changes);
         }
     });
     $widget->bindToController();
     $this->vars['grid'] = $widget;
 }