Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alserom committed Mar 26, 2015
0 parents commit f6322c5
Show file tree
Hide file tree
Showing 24 changed files with 707 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php namespace Romanov\Flashmessage;

use System\Classes\PluginBase;
use Backend;

class Plugin extends PluginBase
{

public function pluginDetails()
{
return [
'name' => 'romanov.flashmessage::lang.plugin.name',
'description' => 'romanov.flashmessage::lang.plugin.description',
'author' => 'Alexander Romanov',
'icon' => 'icon-bullhorn'
];
}

public function registerSettings()
{
return [
'settings' => [
'label' => 'romanov.flashmessage::lang.plugin.name',
'description' => 'romanov.flashmessage::lang.plugin.description',
'icon' => 'icon-bullhorn',
'url' => Backend::url('romanov/flashmessage/settings'),
'order' => 501,
'category' => 'system::lang.system.categories.cms',
'keywords' => 'flash message',
'homepage' => 'https://github.com/romanov-acc/octobercms_flashmessage'
],
];
}

public function registerComponents()
{
return [
'Romanov\Flashmessage\Components\FlashMessage' => 'flashmessage',
'Romanov\Flashmessage\Components\FormError' => 'formerrormessages',
];
}

}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Flash Message component
Display flash messages on front-end
## Install
Romanov.FlashMessage
2 changes: 2 additions & 0 deletions assets/js/bootstrap-notify.min.js

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

27 changes: 27 additions & 0 deletions assets/js/formmode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$(window).on('ajaxErrorMessage', function(event, message){
event.preventDefault();
});
$('button[type="submit"]').click( function(event)
{
var form = $(this).closest('form')[0];
$(form).on('ajaxError', function(event, obj, context, status){
var message;
if(typeof status.responseJSON === 'undefined') {
message = status.responseText.match(/^\"(.*)\"\s/)[1];
} else {
message = status.responseJSON.X_OCTOBER_ERROR_FIELDS;
}
$('.form-group').removeClass('has-error');
$('.form-group .romanov_err_label').remove();
if( typeof message === 'object' ) {
for(var key in message) {
$(this).find('input[name="'+ key +'"]').parent().addClass('has-error');
$(this).find('input[name="'+ key +'"]').before('' +
'<div class="romanov_err_label"><label class="text-danger">' +
message[key][0]+'</label></div>');
}
} else {
alert(message);
}
});
});
52 changes: 52 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
$(window).on('ajaxErrorMessage', function(event, message){
event.preventDefault();
});

$(window).on('ajaxError', function(event, obj, context, status) {
var message;
var showfm = function(message){
if(document.flashflag){
document.romanov_flashoptions.message = message[key][0];
document.romanov_flashsettings.type = 'danger';
$.notify(document.romanov_flashoptions, document.romanov_flashsettings);
}else{
$.notify({
message: message[key][0]
},{
type: 'danger',
placement: {
from: "top",
align: "center"
},
delay: 10000
});
}
}
if (typeof status.responseJSON === 'undefined') {
message = status.responseText.match(/^\"(.*)\"\s/)[1];
} else {
message = status.responseJSON.X_OCTOBER_ERROR_FIELDS;
}
if( typeof message === 'object' ) {
for (var key in message) {
showfm(message);
}
}else{
showfm(message);
}
});

$(document).ready(function(){
$.request('onShowFlashMsg', {
success: function(data){
if(data != ''){
$.each(data.msgs, function(type, msg) {
var t = type == 'error' ? 'danger' : type;
data.options.message = msg;
data.settings.type = t;
$.notify(data.options, data.settings);
});
}
}
});
});
97 changes: 97 additions & 0 deletions components/FlashMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php namespace Romanov\Flashmessage\Components;

use Cms\Classes\ComponentBase;
use Romanov\Flashmessage\Models\Setting as FlashConfigur;

class FlashMessage extends ComponentBase
{
public $conf_id;
public $settings;
public $options;
public $flag = false;

public function componentDetails()
{
return [
'name' => 'romanov.flashmessage::lang.plugin.name',
'description' => 'romanov.flashmessage::lang.plugin.description'
];
}

public function defineProperties()
{
return [
'configuration' => [
'title' => 'romanov.flashmessage::lang.settings.conftitle',
'type' => 'dropdown',
'default' => '',
'showExternalParam' => false,
],
];
}

public function onRun() {
$this->addJs('/plugins/romanov/flashmessage/assets/js/bootstrap-notify.min.js');
$this->addJs('/plugins/romanov/flashmessage/assets/js/main.js');
if($this->property('configuration')){
$this->flag = true;
$this->getParam();
}
}

public function onShowFlashMsg(){
$msg = \Flash::all();
if($msg) {
$res['msgs'] = $msg;
if($this->property('configuration')) {
$data = FlashConfigur::find($this->property('configuration'))->toArray();
$conf = $this->combineSettings($data);
$res['options'] = $conf['options'];
$res['settings'] = $conf['settings'];
}else{
$res['options'] = [];
$res['settings'] = [];
}
return $res;
}
}

public function getConfigurationOptions()
{
$arr = FlashConfigur::lists('title', 'id');
$arr[''] = '...';
return $arr;
}

private function getParam(){
$data = FlashConfigur::find($this->property('configuration'))->toArray();
$conf = $this->combineSettings($data);
$this->options = $conf['options'];
$this->settings = $conf['settings'];
}

private function checkArray($array){
$arr = array_where($array, function($key, $value)
{
if(is_array($value)){
return $this->checkArray($value);
}
return !empty($value);
});
return $arr;
}

private function combineSettings($data){
$res['options'] = $this->checkArray(json_decode($data['options'],true));
$s = json_decode($data['settings'],true);
$sp = json_decode($data['settingsplacement'],true);
$so = json_decode($data['settingsoffset'],true);
$sa = json_decode($data['settingsanimate'],true);
$s['placement'] = $sp;
$s['animate'] = $sa;
if(!$s['offset']) $s['offset'] = $so;
$res['settings'] = $this->checkArray($s);
return $res;
}

}
24 changes: 24 additions & 0 deletions components/FormError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php namespace Romanov\Flashmessage\Components;

use Cms\Classes\ComponentBase;

class FormError extends ComponentBase
{

public function componentDetails()
{
return [
'name' => 'romanov.flashmessage::lang.formerror.title',
'description' => 'romanov.flashmessage::lang.formerror.description'
];
}

public function defineProperties()
{
return [];
}

public function onRun() {
$this->addJs('/plugins/romanov/flashmessage/assets/js/formmode.js');
}
}
9 changes: 9 additions & 0 deletions components/flashmessage/default.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
{% if __SELF__.flag == true %}
document.flashflag = true;
{%else%}
document.flashflag = false;
{% endif %}
document.romanov_flashoptions = {{ __SELF__.options|json_encode|raw }};
document.romanov_flashsettings = {{ __SELF__.settings|json_encode|raw }};
</script>
Empty file.
26 changes: 26 additions & 0 deletions controllers/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php namespace Romanov\Flashmessage\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

class Settings extends Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController'
];

public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';

public function __construct()
{
parent::__construct();

BackendMenu::setContext('Romanov.Flashmessage', 'flashmessage', 'settings');
}




}
5 changes: 5 additions & 0 deletions controllers/settings/_list_toolbar.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div data-control="toolbar">
<a href="<?= Backend::url('romanov/flashmessage/settings/create') ?>" class="btn btn-primary oc-icon-plus">
<?= e(trans('romanov.flashmessage::lang.settings.new')) ?>
</a>
</div>
31 changes: 31 additions & 0 deletions controllers/settings/config_form.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ===================================
# Form Behavior Config
# ===================================

# Record name
name: Setting

# Model Form Field configuration
form: $/romanov/flashmessage/models/setting/fields.yaml

# Model Class name
modelClass: Romanov\Flashmessage\Models\Setting

# Default redirect location
defaultRedirect: romanov/flashmessage/settings

# Create page
create:
title: romanov.flashmessage::lang.settings.new
redirect: romanov/flashmessage/settings/update/:id
redirectClose: romanov/flashmessage/settings

# Update page
update:
title: romanov.flashmessage::lang.settings.edit
redirect: romanov/flashmessage/settings
redirectClose: romanov/flashmessage/settings

# Preview page
preview:
title: romanov.flashmessage::lang.settings.preview
44 changes: 44 additions & 0 deletions controllers/settings/config_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ===================================
# List Behavior Config
# ===================================

# Model List Column configuration
list: $/romanov/flashmessage/models/setting/columns.yaml

# Model Class name
modelClass: Romanov\Flashmessage\Models\Setting

# List Title
title: romanov.flashmessage::lang.settings.title

# Link URL for each record
recordUrl: romanov/flashmessage/settings/update/:id

# Message to display if the list is empty
noRecordsMessage: backend::lang.list.no_records

# Records to display per page
recordsPerPage: 20

# Displays the list column set up button
showSetup: true

# Displays the sorting link on each column
showSorting: true

# Default sorting column
# defaultSort:
# column: created_at
# direction: desc

# Display checkboxes next to each record
# showCheckboxes: true

# Toolbar widget configuration
toolbar:
# Partial for toolbar buttons
buttons: list_toolbar

# Search widget configuration
search:
prompt: backend::lang.list.search_prompt
Loading

0 comments on commit f6322c5

Please sign in to comment.