Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom modal dialog no selection items #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/BulkButtonWidget.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
<?php

namespace johnitvn\ajaxcrud;

use yii\base\Widget;
use yii\helpers\Html;

class BulkButtonWidget extends Widget{

public $buttons;

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

}

public function run(){
$content = '<div class="pull-left">'.
'<span class="glyphicon glyphicon-arrow-right"></span>&nbsp;&nbsp;With selected&nbsp;&nbsp;'.
$this->buttons.
'</div>';
return $content;
}
class BulkButtonWidget extends Widget {

use TranslationTrait;

public $buttons;

public function init() {
parent::init();
$this->initI18N(__DIR__, 'ajaxcrud');
}

public function run() {
$content = '<div class="pull-left">' .
'<span class="glyphicon glyphicon-arrow-right"></span>&nbsp;&nbsp;' . \Yii::t('ajaxcrud', 'With selected') . '&nbsp;&nbsp;' .
$this->buttons .
'</div>';
return $content;
}

}

?>
60 changes: 60 additions & 0 deletions src/TranslationTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2017
* @version 1.8.8
*/

namespace johnitvn\ajaxcrud;

use Yii;
use yii\helpers\ArrayHelper;

/**
* TranslationTrait manages methods for all translations used in Krajee extensions
*
* @property array $i18n
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.8.8
*/
trait TranslationTrait
{
/**
* Yii i18n messages configuration for generating translations
*
* @param string $dir the directory path where translation files will exist
* @param string $cat the message category
*
* @return void
*/
public function initI18N($dir = '', $cat = '')
{
if (empty($cat) && empty($this->_msgCat)) {
return;
}
if (empty($cat)) {
$cat = $this->_msgCat;
}
if (empty($dir)) {
$reflector = new \ReflectionClass(get_class($this));
$dir = dirname($reflector->getFileName());
}
Yii::setAlias("@{$cat}", $dir);
$config = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => "@{$cat}/messages",
'forceTranslation' => true
];
$globalConfig = ArrayHelper::getValue(Yii::$app->i18n->translations, "{$cat}*", []);
if (!empty($globalConfig)) {
$config = array_merge($config, is_array($globalConfig) ? $globalConfig : (array) $globalConfig);
}
if (!empty($this->i18n) && is_array($this->i18n)) {
$config = array_merge($config, $this->i18n);
}
Yii::$app->i18n->translations["{$cat}*"] = $config;
}
}
29 changes: 27 additions & 2 deletions src/assets/ModalRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,31 @@ function ModalRemote(modalId) {

}

/**
* Show the dialog no selection
* @param {string} title The title of modal
* @param {string} message The message for ask user
* @param {string} okLabel The label of ok button
*/
this.noSelectionModal = function (title, message, okLabel) {
this.show();

if (title !== undefined) {
this.setTitle(title);
}
// Add form for user input if required
this.setContent(message);

this.addFooterButton(
okLabel === undefined ? this.defaults.cancelLabel : okLabel,
'button',
'btn btn-default btn-flat pull-left',
function (e) {
this.hide();
}
);
}

/**
* Open the modal
* HTML data attributes for use in local confirm
Expand Down Expand Up @@ -379,8 +404,8 @@ function ModalRemote(modalId) {
$(elm).hasAttr('href') ? $(elm).attr('href') : $(elm).attr('data-url'),
$(elm).hasAttr('data-request-method') ? $(elm).attr('data-request-method') : 'GET',
bulkData
)
} else {
);
}else {
this.doRemote(
$(elm).hasAttr('href') ? $(elm).attr('href') : $(elm).attr('data-url'),
$(elm).hasAttr('data-request-method') ? $(elm).attr('data-request-method') : 'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/assets/ModalRemote.min.js

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

10 changes: 3 additions & 7 deletions src/assets/ajaxcrud.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ $(document).ready(function () {
});

if (selectedIds.length == 0) {
// If no selected ID's show warning
modal.show();
modal.setTitle('No selection');
modal.setContent('You must select item(s) to use this action');
modal.addFooterButton("Close", 'btn btn-default', function (button, event) {
this.hide();
});
modal.noSelectionModal($(elm).attr('data-no-selection-title'),
$(elm).attr('data-no-selection-message'),
$(elm).attr('data-no-selection-ok'));
} else {
// Open modal
modal.open(this, selectedIds);
Expand Down
2 changes: 1 addition & 1 deletion src/assets/ajaxcrud.min.js

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

5 changes: 5 additions & 0 deletions src/messages/en/ajaxcrud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'With selected' => ''
];
5 changes: 5 additions & 0 deletions src/messages/es-MX/ajaxcrud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'With selected' => 'Con selección'
];