namespace App\Fields;
-use Cubist\Backpack\Magic\Fields\SelectFromArray;
+use Cubist\Backpack\Magic\Fields\SelectFromModel;
-class FluidbookTheme extends SelectFromArray
+class FluidbookTheme extends SelectFromModel
{
protected $_adminType = 'fluidbook_theme_selector';
protected $_viewNamespace = 'fields';
- public function getOptions()
+ public function __construct($attributes)
{
- return self::getThemeSelectorOptions();
- }
-
- public static function getThemeSelectorOptions()
- {
- $res = [];
- foreach (\App\Models\FluidbookTheme::orderBy('id', 'DESC')->get() as $theme) {
- $res[$theme['id']] = $theme->name . ' (#' . $theme->id . ')';
- }
- return $res;
+ $attributes['optionsmodel'] = \App\Models\FluidbookTheme::class;
+ $attributes['attribute'] = 'nameAndId';
+ $attributes['optionsmodel_orderby'] = 'id';
+ $attributes['optionsmodel_orderby_way'] = 'desc';
+ parent::__construct($attributes);
}
}
$newtheme->owner = Auth::id();
$newtheme->push();
- copy(GenerateThemePreview::getPreviewPath($id), GenerateThemePreview::getPreviewPath($newtheme->id));
-
return $newtheme->id;
}
class UpdateWS2ThemeTable extends Base
{
- protected $id = 'all';
+ protected $id = 'all';
protected $_fileFields = [];
protected $_colorFields = [];
$data[] = $this->_handleTheme($theme);
$t->where('theme_id', '=', $this->id)->delete();
}
-// dd($data);
$t->insert($data);
}
{
if (self::$updateWS2ViewOnChange) {
if (null !== $id) {
+ start_measure('update_theme_table', 'Update ws2 theme');
dispatch(new UpdateWS2ThemeTable($id))->onConnection('sync');
+ stop_measure('update_theme_table');
}
dispatch(new UpdateWS2ThemeTable('all'))->onQueue('theme');
}
}
return '<img src="data:image/' . $type . ';base64,' . $b . '" width="200" height="140" alt="" />';
}
+
+ public function getNameAndIdAttribute()
+ {
+ return $this->getAttribute('name') . ' (#' . $this->getAttribute('id') . ')';
+ }
+
+ public function replicate(array $except = null)
+ {
+ $currentId = $this->id;
+
+ $res = parent::replicate($except);
+ $newId = $res->id;
+ copy(GenerateThemePreview::getPreviewPath($currentId), GenerateThemePreview::getPreviewPath($newId));
+
+ return $res;
+ }
}
width: 40%;
vertical-align: top;
padding: 0 0 0 20px;
- white-space: normal;
}
.themeSelector .actions a {
return false;
});
- $(document).on('click', 'button[type="submit"].btn-success', function () {
- $(window).on('unload', function () {
+ $(window).on('unload', function () {
+ try {
window.parent.crud.table.ajax.reload();
- window.parent.jQuery.featherlight.current().close();
- return true;
- });
+ } catch (e) {
+
+ }
+ window.parent.jQuery.featherlight.current().close();
return true;
});
});