diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 1147bdf9c4f..61bc1d99a5d 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -61,6 +61,11 @@ $application->registerRoutes( 'url' => '/api/v1/showhidden', 'verb' => 'POST' ], + [ + 'name' => 'API#showGridView', + 'url' => '/api/v1/showgridview', + 'verb' => 'POST' + ], [ 'name' => 'view#index', 'url' => '/', diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 441b8f0a12f..357b1b06016 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -328,7 +328,8 @@ this.$el.find('thead th .columntitle').click(_.bind(this._onClickHeader, this)); // Toggle for grid view - $('#view-toggle').on('click', this._onGridToggle); + this.$showGridView = $('input#showgridview'); + this.$showGridView.on('change', _.bind(this._onGridviewChange, this)); this._onResize = _.debounce(_.bind(this._onResize, this), 250); $('#app-content').on('appresized', this._onResize); @@ -591,10 +592,20 @@ }, /** - * Event handler for grid view toggle + * Toggle showing gridview by default or not + * + * @returns {undefined} */ - _onGridToggle: function() { - $('.list-container').toggleClass('view-grid'); + _onGridviewChange: function() { + var show = this.$showGridView.is(':checked'); + $.post(OC.generateUrl('/apps/files/api/v1/showgridview'), { + show: show + }); + this.$showGridView.next('#view-toggle') + .removeClass('icon-toggle-filelist icon-toggle-pictures') + .addClass(show ? 'icon-toggle-filelist' : 'icon-toggle-pictures') + + $('.list-container').toggleClass('view-grid', show); }, /** diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 9443b9776ae..3c1eb6e43fb 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -267,6 +267,18 @@ class ApiController extends Controller { return new Response(); } + /** + * Toggle default for files grid view + * + * @NoAdminRequired + * + * @param bool $show + */ + public function showGridView($show) { + $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show); + return new Response(); + } + /** * Toggle default for showing/hiding xxx folder * diff --git a/apps/files/list.php b/apps/files/list.php index 93044d4c587..3b54d5ed242 100644 --- a/apps/files/list.php +++ b/apps/files/list.php @@ -22,11 +22,14 @@ */ $config = \OC::$server->getConfig(); +$userSession = \OC::$server->getUserSession(); // TODO: move this to the generated config.js $publicUploadEnabled = $config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'); +$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', false); // renders the controls and table headers template $tmpl = new OCP\Template('files', 'list', ''); $tmpl->assign('publicUploadEnabled', $publicUploadEnabled); +$tmpl->assign('showgridview', $showgridview); $tmpl->printPage(); diff --git a/apps/files/templates/list.php b/apps/files/templates/list.php index c77cbb4d7c1..0c92cf8a1d4 100644 --- a/apps/files/templates/list.php +++ b/apps/files/templates/list.php @@ -24,7 +24,9 @@ - + checked="checked" /> + - +