Exemplo n.º 1
0
 public function run()
 {
     $this->defaultLabel = Yii::t('app', $this->defaultLabel);
     self::$count++;
     if ($this->id === null) {
         $this->id = 'multi-select-' . self::$count;
     }
     if ($this->name === null) {
         $this->name = $this->model->formName() . '[' . $this->attribute . '][]';
     }
     $list = [$this->defaultIndex => $this->defaultLabel] + $this->items;
     $table = $this->getSelectedItems($this->items);
     $params = ['list' => $list, 'table' => $table, 'label' => $this->label, 'id' => $this->id, 'name' => $this->name, 'ajax' => $this->ajax, 'sortable' => $this->sortable];
     $view = $this->getView();
     // @todo
     // $errorFunction =
     $json = \yii\helpers\Json::encode(['addUrl' => $this->addUrl, 'ajax' => $this->ajax, 'defaultIndex' => $this->defaultIndex, 'removeUrl' => $this->removeUrl, 'selectedItems' => $this->selectedItems, 'ajaxData' => $this->ajaxData, 'errorFunction' => new JsExpression($this->errorFunction), 'successFunction' => new JsExpression($this->successFunction)]);
     if (self::$count == 1) {
         $view = $this->getView();
         JuiAsset::register($view);
         $view->registerJs("jQuery.fn.multiSelect = function(params){\n                var \$multiSelect = \$(this);\n                for(var key in params.selectedItems){\n                    \$multiSelect.find('select.list option[value=\"' + params.selectedItems[key] + '\"]').eq(0).addClass('hidden');\n                }\n                \$multiSelect.on('click', 'table a.remove', function(){\n                    \$this = \$(this);\n                    var \$tr = \$this.parents('tr').eq(0);\n                    var \$td = \$tr.find('td').eq(0);\n                    if(params.ajax){\n                        var data = params.ajaxData;\n                        data.id = \$tr.attr('data-id');\n                        \$.ajax({\n                            'data' : data,\n                            'dataType' : 'json',\n                            'success' : function(data){\n                                if(data.status == 1){\n                                    \$multiSelect.find('select.list').find('option[value=\"' + \$tr.attr('data-id') + '\"]').removeClass('hidden');\n                                    \$tr.remove();\n                                    params.successFunction(data);\n                                }else{\n                                    params.errorFunction(data);\n                                }\n                            },\n                            'type' : 'get',\n                            'url' : params.removeUrl\n                        });\n                    }else{\n                        \$multiSelect.find('select.hidden').find('option[value=\"' + \$tr.attr('data-id') + '\"]').remove();\n                        \$tr.remove();\n                        \$multiSelect.find('select.list').find('option[value=\"' + \$tr.attr('data-id') + '\"]').removeClass('hidden');\n                    }\n                    return false;\n                }).on('change', 'select', function(){\n                    var \$this= \$(this);\n                    if(\$this.val() != params.defaultIndex){\n                        var \$item = \$this.find('option[value=\"' + \$this.val() + '\"]');\n                        var \$table = \$multiSelect.find('table').eq(0);\n                        var \$clone = \$table.find('tr.hidden').eq(0).clone().removeClass('hidden').attr('data-id', \$this.val());\n                        \$clone.find('td').eq(0).text(\$item.text());\n                        \$input = \$('<input type=hidden>').val(\$this.val()).attr(\"name\", \"" . $this->name . "\");\n                        \$clone.append(\$input);\n                        if(params.ajax){\n                            var data = params.ajaxData;\n                            data.id = \$this.val();\n                            \$.ajax({\n                                'data' : data,\n                                'dataType' : 'json',\n                                'success' : function(data){\n                                    if(data.status == 1){\n                                        \$item.addClass('hidden');\n                                        \$clone.appendTo(\$table);\n                                        \$this.find('option[value=\"' + params.defaultIndex + '\"]').attr('selected', 'selected');\n                                        params.successFunction(data);\n                                    }else{\n                                        params.errorFunction(data);\n                                    }\n                                },\n                                'tyte' : 'get',\n                                'url' : params.addUrl\n                            });\n                        }else{\n                            \$('<option></option>').attr('value', \$this.val()).attr('selected', 'selected').text(\$item.text()).appendTo(\$multiSelect.find('select.hidden').eq(0));\n                            \$item.addClass('hidden');\n                            \$clone.appendTo(\$table);\n                        }\n                    }\n                });\n                }", View::POS_END);
     }
     $view->registerJs("jQuery('#" . $this->id . "').multiSelect(" . $json . ");");
     if ($this->sortable) {
         $view->registerJs("jQuery('#" . $this->id . " table tbody').sortable({placeholder: \"ui-state-highlight\"});");
     }
     echo $this->render('multiSelect', $params);
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function registerClientScript()
 {
     parent::registerClientScript();
     JuiAsset::register($this->view);
     $id = $this->options["id"];
     $this->view->registerJs("\n\n\t    \$('#{$id}').select2('container').find('ul.select2-choices').sortable({\n            containment: 'parent',\n            start: function() { \$('#{$id}').select2('onSortStart'); },\n            update: function() { \$('#{$id}').select2('onSortEnd'); }\n        });\n        ");
 }
Exemplo n.º 3
0
 /**
  * Registers wysihtml5 plugin and the related events
  */
 protected function registerClientScript()
 {
     $view = $this->getView();
     DatePickerAsset::register($view);
     JuiAsset::register($view);
     $id = $this->options['id'];
     $options = Json::encode($this->clientOptions);
     $view->registerJs("jQuery('#{$id}').progressiveDatePicker('{$this->options['formattedValue']}', {$options});");
 }
Exemplo n.º 4
0
 /**
  * Register asset bundles
  */
 public function registerAssetBundle()
 {
     if (isset($this->clientOptions['plugins']) && in_array('drag_drop', $this->clientOptions['plugins'])) {
         JuiAsset::register($this->getView());
     }
     MicroPluginAsset::register($this->getView());
     SifterAsset::register($this->getView());
     SelectizeAsset::register($this->getView());
 }
Exemplo n.º 5
0
 /**
  * Runs the widget.
  */
 public function run()
 {
     $id = $this->options['id'];
     $view = $this->getView();
     $options = Json::encode(['options' => $this->clientOptions, 'encode' => $this->encode, 'action' => $this->action, 'method' => $this->method]);
     JuiAsset::register($this->getView());
     SortableListViewAsset::register($view);
     $view->registerJs("jQuery('#{$id}').sortableListView({$options});");
     parent::run();
 }
Exemplo n.º 6
0
 /**
  * Registers required script for the plugin to work as jQuery File Uploader
  */
 public function registerClientScript()
 {
     Html::addCssClass($this->wrapperOptions, " single-media upload-kit");
     AttachmentUploadAsset::register($this->getView());
     if ($this->sortable) {
         JuiAsset::register($this->getView());
     }
     $options = Json::encode($this->clientOptions);
     $this->getView()->registerCss(".single-media .upload-kit-input {\n    height: 150px;\n    width: 100%;\n}\n.single-media .upload-kit-item  {\n\tmargin:0;\n}\n.single-media .upload-kit-item.image > img {\n    height: 100%;\n    width: 100%;\n    border-radius: 7px;\n}\n\n            ");
     $this->getView()->registerJs("jQuery('#{$this->options['id']}').attachmentUpload({$options});");
 }
 public function run()
 {
     $view = $this->getView();
     ParameterAsset::register($view);
     JuiAsset::register($view);
     if (substr(\Yii::$app->language, 0, 2) !== 'en') {
         $assetBundle = DatePickerLanguageAsset::register($view);
         $assetBundle->language = \Yii::$app->language;
     }
     Select2Asset::register($view);
     $view->registerJs("\$('#" . $this->getId() . "').ParameterWidget(" . $this->getParameterWidgetOptions() . ");");
     return $this->render('parameter', ['widgetID' => $this->getId(), 'autoShow' => $this->autoShow]);
 }
 public function init()
 {
     parent::init();
     $id = $this->getId();
     $this->options['id'] = $id;
     $classes = isset($this->options['class']) ? $this->options['class'] : '';
     $classes .= ' sortable';
     $this->options['class'] = trim($classes);
     $view = $this->getView();
     JuiAsset::register($view);
     $url = Url::toRoute($this->orderUrl);
     $sortOpts = array_merge($this->sortOptions, ['axis' => 'y', 'items' => '[data-key]', 'update' => new JsExpression("function(e, ui) {\n                jQuery('#{$this->id}').addClass('sorting');\n                jQuery.ajax({\n                    type: 'POST',\n                    url: '{$url}',\n                    data: {\n                        key: ui.item.data('key'),\n                        pos: ui.item.index('[data-key]')\n                    },\n                    complete: function() {\n                        jQuery('#{$this->id}').removeClass('sorting');\n                    }\n                });\n            }")]);
     $sortJson = Json::encode($sortOpts);
     $view->registerJs("jQuery('#{$id}').sortable({$sortJson});");
 }
 public function init()
 {
     parent::init();
     $classes = isset($this->options['class']) ? $this->options['class'] : '';
     $classes .= ' sortable';
     $this->options['class'] = trim($classes);
     $view = $this->getView();
     JuiAsset::register($view);
     $url = Url::toRoute($this->orderUrl);
     $sortOpts = array_merge($this->sortOptions, ['axis' => 'y', 'helper' => new JsExpression('function(e, ui) {
             ui.children().each(function() {
                $(this).width($(this).width());
             });
             return ui;
         }'), 'update' => new JsExpression("function(e, ui) {\n                jQuery('#{$this->id}').addClass('sorting');\n                jQuery.ajax({\n                    type: 'POST',\n                    url: '{$url}',\n                    data: {\n                        key: ui.item.data('key'),\n                        pos: ui.item.index()\n                    },\n                    complete: function() {\n                        jQuery('#{$this->id}').removeClass('sorting');\n                    }\n                });\n            }")]);
     $sortJson = Json::encode($sortOpts);
     $id = $this->getId();
     $view->registerJs("var id = {$id}; var sortJson = {$sortJson}; jQuery('#{$id} tbody').sortable({$sortJson});");
 }
Exemplo n.º 10
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     parent::run();
     $view = $this->getView();
     JuiAsset::register($view);
     $id = $this->options['id'];
     if ($this->clientOptions !== false) {
         $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
         $js = "jQuery('#{$id}').menu({$options});";
         $view->registerJs($js);
     }
     if (!empty($this->clientEvents)) {
         $js = [];
         foreach ($this->clientEvents as $event => $handler) {
             $js[] = "jQuery('#{$id}').on('menu{$event}', {$handler});";
         }
         $view->registerJs(implode("\n", $js));
     }
 }
Exemplo n.º 11
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     echo $this->renderWidget() . "\n";
     $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id'];
     $language = $this->language ? $this->language : Yii::$app->language;
     if (strncmp($this->dateFormat, 'php:', 4) === 0) {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4), 'date', $language);
     } else {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDateIcuToJui($this->dateFormat, 'date', $language);
     }
     if ($language != 'en-US') {
         $view = $this->getView();
         $bundle = DatePickerLanguageAsset::register($view);
         if ($bundle->autoGenerate) {
             $view->registerJsFile($bundle->baseUrl . "/ui/i18n/datepicker-{$language}.js", ['depends' => [JuiAsset::className()]]);
         }
         $options = Json::encode($this->clientOptions);
         $view->registerJs("\$('#{$containerID}').datepicker(\$.extend({}, \$.datepicker.regional['{$language}'], {$options}));");
     } else {
         $this->registerClientOptions('datepicker', $containerID);
     }
     $this->registerClientEvents('datepicker', $containerID);
     JuiAsset::register($this->getView());
 }
Exemplo n.º 12
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     echo $this->renderWidget() . "\n";
     $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id'];
     $language = $this->language ? $this->language : Yii::$app->language;
     if (strncmp($this->dateFormat, 'php:', 4) === 0) {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4));
     } else {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDateIcuToJui($this->dateFormat, 'date', $language);
     }
     if ($language !== 'en-US') {
         $view = $this->getView();
         $assetBundle = DatePickerLanguageAsset::register($view);
         $assetBundle->language = $language;
         $options = Json::htmlEncode($this->clientOptions);
         $language = Html::encode($language);
         $view->registerJs("\$('#{$containerID}').datepicker(\$.extend({}, \$.datepicker.regional['{$language}'], {$options}));");
     } else {
         $this->registerClientOptions('datepicker', $containerID);
     }
     $this->registerClientEvents('datepicker', $containerID);
     JuiAsset::register($this->getView());
 }
Exemplo n.º 13
0
 /**
  * Registers required script for the plugin to work as jQuery File Uploader
  */
 public function registerClientScript()
 {
     UploadAsset::register($this->getView());
     $options = Json::encode($this->clientOptions);
     if ($this->sortable) {
         JuiAsset::register($this->getView());
     }
     $this->getView()->registerJs("jQuery('#{$this->getId()}').yiiUploadKit({$options});");
 }
Exemplo n.º 14
0
$script = <<<JavaScript
\$("input[id\$='columnsorder']").val(\$('#sortable-form').serialize());
\$( "#sortable" ).sortable({
    update: function(event, ui) {
        \$("input[id\$='columnsorder']").val(\$('#sortable-form').serialize());
        changeOrderNumeration();
    }
});
function changeOrderNumeration() {
    \$.each(\$('#sortable .order-numeration'), function(index, item){
        \$(this).html(index+1+'.');
    });
}
JavaScript;
$this->registerJs($script);
\yii\jui\JuiAsset::register($this);
$fields[0]['length'] = ['formMethod' => 'textInput', 'attribute' => 'length', 'arguments' => []];
$fields[0]['delimiter'] = ['formMethod' => 'textInput', 'attribute' => 'delimiter', 'arguments' => []];
$fields[0]['enclosure'] = ['formMethod' => 'textInput', 'attribute' => 'enclosure', 'arguments' => []];
$fields[0]['escape'] = ['formMethod' => 'textInput', 'attribute' => 'escape', 'arguments' => []];
$fields[0]['header'] = ['formMethod' => 'checkbox', 'attribute' => 'header', 'arguments' => []];
$fields[0]['parser_options'] = Html::activeHiddenInput($model, 'parser_options');
$fields[0]['parser_class'] = Html::activeHiddenInput($model, 'parser_class');
$fields[0]['columnsOrder'] = \yii\helpers\Html::activeHiddenInput($model, 'columnsOrder');
?>
<div class="row">
    <div class="col-md-6">
        <?php 
echo $this->renderDefault('_form', ['model' => $model, 'fields' => $fields, 'relations' => $relations]);
?>
    </div>
Exemplo n.º 15
0
<?php

use yii\helpers\Html;
use yii\jui\JuiAsset;
use yii\helpers\Url;
use yii\web\View;
use mdm\widgets\TabularInput;
use backend\models\accounting\GlTemplate;
JuiAsset::register($this);
$opts = json_encode(['tmplate_url' => Url::to(['journal-templates'])]);
$this->registerJs("var biz = {$opts};", View::POS_HEAD);
$this->registerJs($this->render('_script-by-template.js'));
$detailFunc = function ($model, $key) {
    $result = Html::activeHiddenInput($model, "[{$key}]id", ['data-field' => 'id']);
    $result .= Html::tag('td', Html::tag('span', Html::getAttributeValue($model, "[{$key}]es[name]"), ['data-field' => 'name']));
    $result .= Html::tag('td', Html::activeTextInput($model, "[{$key}]amount", ['data-field' => 'amount', 'class' => 'form-control']));
    $result .= Html::tag('td', Html::tag('a', '<i class="fa fa-minus"></i>'), ['data-action' => 'delete']);
    return $result;
};
?>

<div class="col-lg-12 no-padding no-margin">
    <table class="table table-hover" id="table-templates">
        <thead>
            <tr>
                <th>Template</th>
                <th>Amount</th>
                <th style="width: 5%">#</th>
            </tr>
            <tr>
                <th><input type="hidden" id="inp-template-id">
Exemplo n.º 16
0
    public function init()
    {
        JuiAsset::register($this->view);
        parent::init();
        FileHelper::removeDirectory($this->getModule()->getUserDirPath());
        // Delete all uploaded files in past
        $this->pluginOptions = array_replace($this->pluginOptions, ['uploadUrl' => Url::toRoute('/file/file/upload'), 'initialPreview' => $this->model->isNewRecord ? [] : $this->model->getInitialPreview(), 'initialPreviewConfig' => $this->model->isNewRecord ? [] : $this->model->getInitialPreviewConfig(), 'uploadAsync' => false, 'otherActionButtons' => '<button type="button" class="js-caption-rename rename-button btn btn-xs btn-default" title="Переименовать" {dataKey}><i class="glyphicon glyphicon-comment text-danger"></i></button>' . '<input type="checkbox" class="jsFileMain" title="Главная" {dataKey}>', 'slugCallback' => new JsExpression(<<<JS
function(text) {return text.split(/(\\|\\/)/g).pop();}
JS
), 'layoutTemplates' => ['footer' => '
<div class="file-thumbnail-footer">
    <div style="margin:5px 0">
        <input  class="form-control js-custom-caption" value="{caption}" />
    </div>{actions}
</div>']]);
        $this->options = array_replace($this->options, ['id' => $this->id]);
        $urlSetMain = Url::toRoute('/file/file/set-main');
        $urlRenameFile = Url::toRoute('/file/file/rename');
        $js = <<<JS
var fileInput = \$('#file-input');
var form = fileInput.closest('form');
var filesUploaded = false;
var filesToUpload = 0;
var uploadButtonClicked = false;
form.on('beforeSubmit', function() { // form submit event
    if (!filesUploaded && filesToUpload) {
        console.log('upload');
        \$('#file-input').fileinput('upload').fileinput('lock');

        return false;
    }
});

fileInput.on('filebatchpreupload', function() {
    uploadButtonClicked = true;
});

fileInput.on('filebatchuploadsuccess', function() {
    filesUploaded = true;
    \$('#file-input').fileinput('unlock');
    if (uploadButtonClicked) {
        form.submit();
    } else {
        uploadButtonClicked = false;
    }
});

fileInput.on('filebatchselected', function(event, files) {
    filesToUpload = files.length
});

fileInput.on('filecleared', function() {
    filesToUpload = 0;
});
\$('.formInput-{$this->getId()}').on('change', '.jsFileMain', function() {
    var element = \$(this);
    var key = element.data('key');
    \$.ajax(
        '{$urlSetMain}',
        {
            method: "POST",
            data: {
                id:key,
                value:element.prop('checked')
            },
            success: function(data) {
                \$('.formInput-{$this->getId()} .jsFileMain').prop('checked', false);
                if(data.id) {
                     \$('.formInput-{$this->getId()} .jsFileMain[data-key="' + data.id + '"]').prop('checked', true);
                }
            }
        }
    );
});

\$('.formInput-{$this->getId()}').on('click', '.js-caption-rename', function() {
    var element = \$(this);
    var key = element.data('key');
    var input = \$(this).parents('.file-preview-frame').find('.js-custom-caption');
    var name = input.val();
    \$.ajax(
        '{$urlRenameFile}',
        {
            method: "POST",
            data: {
                id: key,
                name: name
            },
            success: function(data) {
            }
        }
    );
});
JS;
        Yii::$app->view->registerJs($js);
    }
Exemplo n.º 17
0
 /**
  * Registers required script for the plugin to work as jQuery File Uploader
  */
 public function registerClientScript()
 {
     Html::addCssClass($this->wrapperOptions, " upload-kit");
     AttachmentUploadAsset::register($this->getView());
     if ($this->sortable) {
         JuiAsset::register($this->getView());
     }
     $options = Json::encode($this->clientOptions);
     $this->getView()->registerJs("jQuery('#{$this->options['id']}').attachmentUpload({$options});");
 }
Exemplo n.º 18
0
 /**
  * Register widget assets.
  */
 public function registerClientScript()
 {
     $view = $this->getView();
     $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id'];
     $options = !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '';
     $asset = TimePickerAsset::register($view);
     if ($this->language !== null) {
         $asset->language = $this->language;
         $bundle = DatePickerLanguageAsset::register($view);
         $view->registerJsFile($bundle->baseUrl . "/ui/i18n/datepicker-{$this->language}.js", ['depends' => [JuiAsset::className()]]);
     }
     if (!empty($this->clientEvents)) {
         foreach ($this->clientEvents as $event => $handler) {
             $view->registerJs("jQuery('#{$containerID}').on('{$event}', {$handler});");
         }
     }
     $view->registerJs("jQuery('#{$containerID}').{$this->mode}picker({$options});");
 }
Exemplo n.º 19
0
 /**
  * Registers a specific jQuery UI widget asset bundle, initializes it with client options and registers related events
  * @param string $name the name of the jQuery UI widget
  * @param string $id the ID of the widget. If null, it will use the `id` value of [[options]].
  */
 protected function registerWidget($name, $id = null)
 {
     if ($id === null) {
         $id = $this->options['id'];
     }
     JuiAsset::register($this->getView());
     $this->registerClientOptions($name, $id);
     $this->registerClientEvents($name, $id);
 }
Exemplo n.º 20
0
 /**
  * Register date picker language on client side
  * @param \yii\web\View $view View context
  */
 public static function registerClientSideDatePickerLanguage($view)
 {
     $language = Yii::$app->language;
     if ($language != 'en-US' && $language != 'en') {
         $bundle = DatePickerLanguageAsset::register($view);
         if ($bundle->autoGenerate) {
             $fallbackLanguage = substr($language, 0, 2);
             if ($fallbackLanguage !== $language && !file_exists(Yii::getAlias($bundle->sourcePath . "/ui/i18n/datepicker-{$language}.js"))) {
                 $language = $fallbackLanguage;
             }
             $view->registerJsFile($bundle->baseUrl . "/ui/i18n/datepicker-{$language}.js", ['depends' => [JuiAsset::className()]]);
             $view->registerJs("\$.kalibao.core.app.datePickerLanguage = \$.datepicker.regional['{$language}'];");
         }
     }
 }