Skip to content

Commit

Permalink
Fixed toggler for stable/testing channel
Browse files Browse the repository at this point in the history
  • Loading branch information
w00fz committed Apr 20, 2016
1 parent 22464b0 commit 69459ec
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
7 changes: 6 additions & 1 deletion classes/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ protected function taskGpmRelease()

// Default release state
$release = 'stable';
$reload = false;

// Get the testing release value if set
if ($this->grav['uri']->param('release') == 'testing') {
if ($this->post['release'] == 'testing') {
$release = 'testing';
}

Expand All @@ -308,7 +309,11 @@ protected function taskGpmRelease()
// Save the configuration
$data->save();
$config->reload();
$reload = true;
}

$this->admin->json_response = ['status' => 'success', 'reload' => $reload];
return true;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions pages/admin/ajax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Generic Ajax

access:
admin.configuration: true
admin.super: true
---
24 changes: 24 additions & 0 deletions themes/grav/app/updates/channel-switcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import $ from 'jquery';
import request from '../utils/request';

const switcher = $('input[type="radio"][name="channel-switch"]');

if (switcher) {
switcher.on('change', (event) => {
let radio = $(event.target);
let url = `${radio.parent('[data-url]').data('url')}`;

request(url, {
method: 'post',
body: {
task: 'gpmRelease',
release: radio.val()
}
},
(response) => {
if (response.reload) {
global.location.reload();
}
});
});
}
1 change: 1 addition & 0 deletions themes/grav/app/updates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import formatBytes from '../utils/formatbytes';
import { Instance as gpm } from '../utils/gpm';
import './check';
import './update';
import './channel-switcher';

export default class Updates {
constructor(payload = {}) {
Expand Down
4 changes: 2 additions & 2 deletions themes/grav/js/admin.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions themes/grav/templates/partials/release-toggle.html.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<form id="gpm-release-toggle">
<div class="switch-toggle switch-grav" data-url="{{ base_url }}/task:gpmRelease">
<input type="radio" value="stable" id="stable" name="mode-switch" class="highlight" {% if config.system.gpm.releases == 'stable' %} checked="checked"{% endif %}>
<div class="switch-toggle switch-grav" data-url="{{ base_url }}/ajax.json/task:gpmRelease">
<input type="radio" value="stable" id="stable" name="channel-switch" class="highlight" {% if config.system.gpm.releases == 'stable' %} checked="checked"{% endif %}>
<label for="stable">{{ "PLUGIN_ADMIN.STABLE"|tu }}</label>
<input type="radio" value="testing" id="testing" name="mode-switch" class="highlight" {% if config.system.gpm.releases == 'testing' %} checked="checked"{% endif %}>
<input type="radio" value="testing" id="testing" name="channel-switch" class="highlight" {% if config.system.gpm.releases == 'testing' %} checked="checked"{% endif %}>
<label for="testing">{{ "PLUGIN_ADMIN.TESTING"|tu }}</label>
<a></a>
</div>
Expand Down

0 comments on commit 69459ec

Please sign in to comment.