Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
added ‘refresh on success’
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Apr 11, 2017
1 parent 91d847c commit 970a216
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
12 changes: 9 additions & 3 deletions fields/opener/assets/js/script.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Opener = ($, $field) ->
this.$download = $field.find('.opener-button a.opener-download')

this.useDownloadLink = this.$opener.hasClass 'download'
this.refresh = this.$opener.hasClass 'refresh'
this.delay = parseInt(this.$opener.attr('data-delay')) #ms
this.jsoncode = String(this.$opener.attr('data-jsoncode'))
this.jsonmessage = String(this.$opener.attr('data-jsonmessage'))
Expand All @@ -30,8 +31,10 @@ Opener = ($, $field) ->
return

this.hasError = (error, msg) ->
if msg == undefined then msg = self.l.error
if msg == undefined or msg.length == 0 then msg = error
if msg == undefined or msg.trim().length == 0
msg = self.l.error
if msg == undefined or msgtrim().length == 0
msg = error

self.$button.addClass('btn-negative')
.children('span').text msg
Expand All @@ -44,7 +47,8 @@ Opener = ($, $field) ->
return

this.hasSuccess = (msg, durl) ->
if msg == undefined then msg = self.l.success
if msg == undefined or msg.trim().length == 0
msg = self.l.success

self.$button.addClass('btn-positive')
self.$button.children('span').text msg
Expand All @@ -63,6 +67,8 @@ Opener = ($, $field) ->
self.$button.children('span').text self.l.default
self.$download.attr 'href', ''
self.$download.attr 'download', ''
if self.refresh
window.location.reload(true)
, self.delay

return
Expand Down
2 changes: 1 addition & 1 deletion fields/opener/assets/js/script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion fields/opener/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,29 @@

$href = url(str::template($field->command, $placeholder));
$download = str::contains($href, c::get('plugin.opener.trigger-download', 'download:yes'));

$openConfig = c::get('plugin.opener.trigger-open', 'open:yes');
$open = str::contains($href, $openConfig);
if($open) {
$href = str_replace('/'.$openConfig, '', $href);
}

$copyConfig = c::get('plugin.opener.trigger-copy', 'copy:yes');
$copy = str::contains($href, $copyConfig);
if($copy) {
$href = str_replace('/'.$copyConfig, '', $href);
}

$refreshConfig = c::get('plugin.opener.trigger-refresh', 'refresh:yes');
$refresh = str::contains($href, $refreshConfig);
if($refresh) {
$href = str_replace('/'.$refreshConfig, '', $href);
}
?>

<div class="<?php echo $fieldname ?>-wrapper">
<div
class="<?php echo $fieldname ?>-button <?php ecco($popup, 'popup ', '') ?><?php ecco($download, 'download ', '') ?><?php ecco($open, 'no-ajax ', '') ?><?php ecco($copy, 'copy-clipboard ', '') ?>"
class="<?php echo $fieldname ?>-button <?php ecco($popup, 'popup ', '') ?><?php ecco($download, 'download ', '') ?><?php ecco($open, 'no-ajax ', '') ?><?php ecco($copy, 'copy-clipboard ', '') ?><?php ecco($refresh, 'refresh ', '') ?>"
data-delay="<?php echo $delay; ?>"
data-jsoncode="<?php echo $code; ?>"
data-jsonmessage="<?php echo $message; ?>"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kirby-opener",
"description": "Kirby Opener is a Kirby CMS Panel Field button that allows you to use placeholders to create dynamic urls which are called with and without ajax response or start downloads.",
"version": "0.7.0",
"version": "0.8.0",
"author": "Bruno Meilick",
"type": "kirby-plugin",
"license": "Commercial"
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Kirby Opener is a Kirby CMS Panel Field button that allows you to use placeholde
- display custom JSON response status messages at the button label
- trigger downloading of files
- trigger clipboard copy of url
- trigger refresh of page on success
- easily extendable *placeholders*
- configural parsing of *json response*

Expand Down Expand Up @@ -272,6 +273,10 @@ You can set these in your `site/config/config.php`.
- default: 'copy:yes'
- command part to tell the plugin js script to trigger clipboard copy of the url. There will be no ajax call. If browser blocks it behaves like with `open:yes`.

### plugin.opener.trigger-refresh
- default: 'refresh:yes'
- command part to tell the plugin js script to trigger a page refresh on success.

![Example](https://github.com/bnomei/kirby-opener/blob/master/example-clipboard.gif)

### plugins.opener.allow-pagemodels
Expand Down

0 comments on commit 970a216

Please sign in to comment.