diff --git a/CHANGELOG.md b/CHANGELOG.md index ccb9700bd..6ba50a5ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +* **Build x** (2014-06-10) + - Form fields can now pass context via their name definnition using syntax `field@context`. + - Added a code editor preferences page. + * **Build 101** (2014-06-06) - Added a global traceLog() helper for help with debugging. - New settings area added to manage Email templates and layouts. diff --git a/modules/backend/ServiceProvider.php b/modules/backend/ServiceProvider.php index bed3178ab..e4d7c8467 100644 --- a/modules/backend/ServiceProvider.php +++ b/modules/backend/ServiceProvider.php @@ -8,6 +8,7 @@ use BackendAuth; use Backend\Classes\WidgetManager; use October\Rain\Support\ModuleServiceProvider; use System\Models\EmailTemplate; +use System\Classes\SettingsManager; class ServiceProvider extends ModuleServiceProvider { @@ -62,6 +63,22 @@ class ServiceProvider extends ModuleServiceProvider ]); }); + /* + * Register settings + */ + SettingsManager::instance()->registerCallback(function($manager){ + $manager->registerSettingItems('October.Backend', [ + 'editor' => [ + 'label' => 'backend::lang.editor.menu_label', + 'description' => 'backend::lang.editor.menu_description', + 'category' => 'System', + 'icon' => 'icon-code', + 'class' => 'Backend\Models\EditorSettings', + 'sort' => 200 + ], + ]); + }); + /* * Register permissions */ diff --git a/modules/backend/behaviors/UserSettingsModel.php b/modules/backend/behaviors/UserSettingsModel.php new file mode 100644 index 000000000..6d630f037 --- /dev/null +++ b/modules/backend/behaviors/UserSettingsModel.php @@ -0,0 +1,94 @@ +model->table = 'backend_user_preferences'; + } + + /** + * Create an instance of the settings model, intended as a static method + */ + public function instance() + { + if (isset(self::$instances[$this->recordCode])) + return self::$instances[$this->recordCode]; + + $item = UserPreferences::forUser(); + $item = $item->scopeFindRecord($this->model, $this->recordCode, $item->userContext)->first(); + + if (!$item) { + $this->model->initSettingsData(); + $this->model->forceSave(); + $this->model->reload(); + $item = $this->model; + } + + return self::$instances[$this->recordCode] = $item; + } + + /** + * Checks if the model has been set up previously, intended as a static method + */ + public function isConfigured() + { + return UserPreferences::forUser()->findRecord($this->recordCode, $item->userContext)->count() > 0; + } + + /** + * Before the model is saved, ensure the record code is set + * and the jsonable field values + */ + public function beforeModelSave() + { + $preferences = UserPreferences::forUser(); + + list($namespace, $group, $item) = $preferences->parseKey($this->recordCode); + $this->model->item = $item; + $this->model->group = $group; + $this->model->namespace = $namespace; + $this->model->user_id = $preferences->userContext->id; + + if ($this->fieldValues) + $this->model->value = $this->fieldValues; + } + + /** + * Checks if a key is legitimate or should be added to + * the field value collection + */ + private function isKeyAllowed($key) + { + /* + * Let the core columns through + */ + if ($key == 'namespace' || $key == 'group') + return true; + + return parent::isKeyAllowed($key); + } +} \ No newline at end of file diff --git a/modules/backend/formwidgets/CodeEditor.php b/modules/backend/formwidgets/CodeEditor.php index e8d758321..c15fad0b7 100644 --- a/modules/backend/formwidgets/CodeEditor.php +++ b/modules/backend/formwidgets/CodeEditor.php @@ -1,5 +1,6 @@ language = $this->getConfig('language', 'php'); $this->showGutter = $this->getConfig('showGutter', true); - $this->theme = $this->getConfig('theme', 'twilight'); - $this->wrapWords = $this->getConfig('wrapWords', false); - $this->fontSize = $this->getConfig('fontSize', false); + $this->theme = $this->getConfig('theme', $editorSettings->theme); + $this->wrapWords = $this->getConfig('wrapWords', $editorSettings->use_wrap); + $this->fontSize = $this->getConfig('fontSize', $editorSettings->font_size); + $this->tabSize = $this->getConfig('tabSize', $editorSettings->tab_size); + $this->useSoftTabs = $this->getConfig('useSoftTabs', !$editorSettings->use_hard_tabs); $this->margin = $this->getConfig('margin', 0); } @@ -79,6 +95,8 @@ class CodeEditor extends FormWidgetBase $this->vars['showGutter'] = $this->showGutter; $this->vars['wrapWords'] = $this->wrapWords; $this->vars['fontSize'] = $this->fontSize; + $this->vars['tabSize'] = $this->tabSize; + $this->vars['useSoftTabs'] = $this->useSoftTabs; $this->vars['theme'] = $this->theme; $this->vars['name'] = $this->formField->getName(); $this->vars['value'] = $this->model->{$this->columnName}; diff --git a/modules/backend/formwidgets/codeeditor/partials/_codeeditor.htm b/modules/backend/formwidgets/codeeditor/partials/_codeeditor.htm index 3d37fd697..2478c27ed 100644 --- a/modules/backend/formwidgets/codeeditor/partials/_codeeditor.htm +++ b/modules/backend/formwidgets/codeeditor/partials/_codeeditor.htm @@ -11,6 +11,8 @@ data-theme="= $theme ?>" data-margin="= $margin ?>" data-font-size="= $fontSize ?>" + data-tab-size="= $tabSize ?>" + data-use-soft-tabs="= $useSoftTabs ?>" data-vendor-path="= URL::to('/modules/backend/formwidgets/codeeditor/assets/vendor/ace') ?>/">