Esempio n. 1
0
 /**
  * @param string $params
  * @return string
  */
 public static function getLangUrl($params = '')
 {
     $langBegin = Yii::$app->getUrlManager()->langBegin;
     if (isset($langBegin['0']) && $langBegin['0'] === Yii::$app->language) {
         return Url::to('@web/' . $params);
     } else {
         return Url::to('@web/' . Yii::$app->language . '/' . $params);
     }
 }
Esempio n. 2
0
    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();
        if (empty($this->tableName)) {
            throw new InvalidConfigException('The "tableName" property must be set.');
        }
        $view = Yii::$app->getView();
        Html::addCssClass($this->buttonOptions, $this->buttonClass);
        if (!$this->tableColumn) {
            $this->tableColumn = $this->attribute;
        }
        $id = Yii::$app->request->post('id');
        $tableColumn = Yii::$app->request->post('tableColumn');
        if (Yii::$app->request->isPost && $tableColumn === $this->tableColumn) {
            /* @var \yii\db\Connection $db */
            $db = Yii::$app->get($this->db);
            $json['r'] = false;
            $query = new Query();
            $row = $query->from($this->tableName)->select(['a' => $this->tableColumn])->where(['id' => $id])->limit(1)->one($db);
            if ($row) {
                if ($row['a']) {
                    $active = false;
                    $result = $this->falseIcon;
                } else {
                    $active = true;
                    $result = $this->trueIcon;
                }
                $update = [$this->tableColumn => $active];
                if (is_array($this->update)) {
                    foreach ($this->update as $column => $value) {
                        if (is_integer($column)) {
                            $update[$value] = new Expression('NOW()');
                        } else {
                            if ($value instanceof \Closure) {
                                $update[$column] = $value($column, $this);
                            } else {
                                $update[$column] = $value;
                            }
                        }
                    }
                }
                $db->createCommand()->update($this->tableName, $update, 'id=:id', [':id' => $id])->execute();
                $json['r'] = true;
                $json['res'] = $result;
            }
            $response = Yii::$app->getResponse();
            $response->clearOutputBuffers();
            $response->setStatusCode(200);
            $response->format = Response::FORMAT_JSON;
            $response->data = $json;
            $response->send();
            Yii::$app->end();
        }
        $view->registerJs('
            $(document).on("click", ".' . $this->buttonClass . '", function(){
                var $btn = $(this);

                $btn.html("' . $this->loading . '");
                $btn.attr("disabled", true);

                $.ajax({
                    url: "' . Url::current() . '",
                    type: "POST",
                    dataType: "json",
                    data: {id: $btn.attr("data-id"), tableColumn: $btn.attr("data-column")},
                }).done(function(d){
                    if(d.r){
                        $btn.html(d.res);
                    }
                }).always(function(jqXHR, textStatus){
                    $btn.attr("disabled", false);
                });

            });
        ');
    }
Esempio n. 3
0
    /**
     * @param $view
     */
    public function registerAssets($view)
    {
        NestableAsset::register($view);
        $view->registerJs('
                $("#' . $this->id . '").nestable(' . Json::encode($this->clientOptions) . ');
                var parentDisabled = ' . ($this->parentCol ? 'true' : 'false') . ';
                var nestableSerialize       = $("#' . $this->id . '").nestable("serialize");
                var nestableLoadingItem = function(id, showLoading){
                    var $loading = $(".nestable-loading-" + id);
                    if (showLoading){
                        $loading.removeClass("hide");
                    } else {
                        $loading.addClass("hide");
                    }
                    return $loading;
                }
                if(!parentDisabled){
                    $(".dd-item").find("[data-action=\'collapse\'],[data-action=\'expand\']").remove();
                }

                $("#' . $this->id . '").on("touchclick", function(e,that,action,$target, $item){
                    if(action == "expand"){
                        var id = $item.attr("data-id");
                        var $this = $(this);
                        var $collapse = $item.children("[data-action=\\"collapse\\"]").hide();
                        nestableLoadingItem(id,true);

                        $.ajax({
                            url: "' . Url::current() . '",
                            type: "get",
                            dataType: "json",
                            beforeSend: function (request){
                                request.setRequestHeader("adm-nestable-ajax", "1");
                                request.setRequestHeader("adm-nestable-id-parent", id);
                            },
                        }).done(function(d){
                            if(d.r){
                                $children = $($item).children("." + that.options.listClass);
                                $children.prepend(d.items);
                                $children.children("li").prepend($(that.options.expandBtnHTML)).prepend($(that.options.collapseBtnHTML)).children("[data-action=\\"collapse\\"]").hide();
                            }
                        }).always(function(jqXHR, textStatus){
                            nestableLoadingItem(id, false);
                            $collapse.show();
                        });
                    } else {
                        $("." + that.options.listClass, $item).empty();
                    }

                });

                $("#' . $this->id . '").on("change", function(e,el) {
                    var id = $(el).attr("data-id");
                    var $this = $(this);
                    var items = $this.nestable("serialize");
                    if(JSON.stringify(items) == JSON.stringify(nestableSerialize)){
                        return;
                    }
                    nestableLoadingItem(id, true);

                    nestableSerialize = items;
                    $.ajax({
                        url: "' . Url::current() . '",
                        type: "POST",
                        dataType: "json",
                        data: {nestable_items: items, "' . Yii::$app->request->csrfParam . '": "' . Yii::$app->request->getCsrfToken() . '"},
                        beforeSend: function (request){
                            request.setRequestHeader("adm-nestable-ajax", "1");
                        },
                    }).done(function(d){
                        if(d.error){
                           alert(error);
                        }
                        if (d.weight){
                            for (var i in d.weight) {
                                $(".nestable-weight-" + i, $this).text(d.weight[i]);
                            }
                        }
                    }).always(function(jqXHR, textStatus){
                        nestableLoadingItem(id, false);
                        if (textStatus !== "success") {

                        }
                    }).fail(function(jqXHR, textStatus, message){
                        alert(message);
                    });
                });

                $("#' . $this->grid->id . ',#' . $this->id . '").addClass("hide");
                $(".btn-adm-nestable-view").on("click", function(e){
                    $(".btn-adm-nestable").trigger("click");
                    return false;
                }).show();

                $(".btn-adm-nestable").on("click", function(e){
                    var $this = $(this);
                    var isNestable = parseInt($this.attr("data-is-nestable"));
                    var text = isNestable ? $this.attr("data-gridview-text") : $this.attr("data-nestable-text");

                    if(isNestable){
                        $("#' . $this->grid->id . '").addClass("hide");
                        $("#' . $this->id . '").removeClass("hide");
                        $this.attr("data-is-nestable", 0);
                    } else {
                        $("#' . $this->id . '").addClass("hide");
                        $("#' . $this->grid->id . '").removeClass("hide");
                        $this.attr("data-is-nestable", 1);
                    }
                    $this.text(text);
                    $(".btn-adm-nestable-view").text(text);
                    return false;
                }).trigger("click");
            ');
    }
Esempio n. 4
0
        <?php 
if (!Adm::getInstance()->user->isGuest) {
    ?>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle dker" data-toggle="dropdown">
                        <?php 
    echo $adm->user->identity->username;
    ?>
 <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li>
                        <a href="<?php 
    echo Url::to(['/' . $adm->id . '/user/update']);
    ?>
"><?php 
    echo Adm::t("header", "Profile", ['dot' => false]);
    ?>
</a>
                    </li>
                    <?php 
    $adm->trigger(Adm::EVENT_INNER_PROFILE_MENU);
    ?>
                    <li>
                        <?php 
    echo Html::a(Adm::t("header", "Logout", ['dot' => false]), ['/' . $adm->id . '/default/logout'], ['data-method' => 'post']);
    ?>
                    </li>
                </ul>
Esempio n. 5
0
        <?php 
echo Html::a(Adm::t('source-message', 'Create Source Message'), ['create'], ['class' => 'btn btn-primary']);
?>


        <?php 
if (Yii::$app->request->get('is-empty')) {
    ?>
            <?php 
    echo Html::a(Adm::t('source-message', 'Only not translation(disable)'), Url::current(['is-empty' => null]), ['class' => 'btn btn-danger']);
    ?>
        <?php 
} else {
    ?>
            <?php 
    echo Html::a(Adm::t('source-message', 'Only not translation'), Url::current(['is-empty' => 1]), ['class' => 'btn btn-primary']);
    ?>
        <?php 
}
?>



    </p>

    <?php 
echo Adm::widget('GridView', ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'kartik\\grid\\SerialColumn'], 'category', 'message', ['attribute' => 'translation', 'format' => 'raw', 'value' => function ($model, $index, $widget) {
    $text = Html::encode(Yii::t($model->category, $model->message, ['dot' => false]));
    $dot = Yii::t($model->category, $model->message, ['dot' => '.']);
    return $text . $dot;
}], ['class' => 'kartik\\grid\\ActionColumn', 'template' => '{update} {delete}', 'width' => '70px']]]);