Exemplo n.º 1
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     //echo $this->model->state;
     //for new record creation
     $modal = [];
     $_state = $this->model->state;
     if ($this->model->isNewRecord || $_state == AppActiveRecord::STATUS_DRAFT) {
         if (\yii::$app->user->can('saveasdraft')) {
             echo '  ';
             AjaxSubmitButton::begin(['label' => 'Save as Draft', 'options' => ['id' => 'saveasdraft-btn', 'class' => 'btn btn-lg btn-warning', 'type' => 'button'], 'ajaxOptions' => ['type' => 'POST', 'url' => Url::toRoute(array_merge(['saveasdraft'], $this->params)), 'success' => new \yii\web\JsExpression('function(data){                        
                         if(data.status){
                             location.href = "' . Url::toRoute(array_merge(['index'])) . '";
                         }
                      }')]]);
             AjaxSubmitButton::end();
             $this->view->registerJs("\$( '#saveasdraft-btn' ).click(function() {\n                \$(this).addClass('disabled');\n            });");
         }
     }
     if (\yii::$app->user->can('create') || \yii::$app->user->can('update')) {
         echo '  ';
         echo Html::submitButton('Save', ['class' => 'btn btn-lg btn-info aftervalidate']);
     }
     if (!$this->model->isNewRecord && $_state != AppActiveRecord::STATUS_DRAFT && $_state != AppActiveRecord::STATUS_SOURCED && ($_state != AppActiveRecord::STATUS_PUBLISH || $_state != AppActiveRecord::STATUS_PUBLISHREADY)) {
         //not in draft, not new, not publish, not ready to ready, can be draft update or sourced
         if ($_state != AppActiveRecord::STATUS_PUBLISH && \yii::$app->user->can('publish')) {
             //not in draft, not new, not publish, not ready to ready
             echo '  ';
             echo Html::submitButton('Publish', ['class' => 'btn btn-lg changeaction btn-success aftervalidate', 'data-url' => Url::toRoute(array_merge(['publish'], $this->params))]);
         } elseif ($_state != AppActiveRecord::STATUS_PUBLISHREADY && $_state != AppActiveRecord::STATUS_PUBLISH && \yii::$app->user->can('sendtopublish')) {
             echo '  ';
             echo Html::submitButton('Send to Publisher', ['class' => 'btn btn-lg changeaction btn-success aftervalidate', 'data-url' => Url::toRoute(array_merge(['sendtopublish'], $this->params))]);
         }
     }
     if ($this->deletebtn && \yii::$app->user->can('delete') && !$this->model->isNewRecord) {
         echo '  ';
         $deletemodal = 'modal-trash';
         $modal[] = ['id' => $deletemodal, 'header' => '<h4>Delete ' . strtolower($this->model->ClassSortNeme()) . ': ' . $this->model->name . '</h4>'];
         echo Html::button($this->deletebtntxt, ['class' => 'btn btn-danger btn-lg', 'title' => Yii::t('yii', 'Unpublish'), 'data-toggle' => 'modal', 'data-target' => '#' . $deletemodal, 'data-remote' => Url::toRoute(['delete', 'id' => $this->model->id])]);
     }
     if ($this->unpublishbtn && $this->model->state == AppActiveRecord::STATUS_PUBLISH && \yii::$app->user->can('unpublish')) {
         echo '&nbsp;&nbsp;';
         $uppublishedmodal = 'modal-unpub';
         $modal[] = ['id' => $uppublishedmodal, 'header' => '<h4>Unpublish ' . strtolower($this->model->ClassSortNeme()) . ': ' . $this->model->name . '</h4>'];
         echo Html::button($this->unpublishbtntxt, ['class' => 'btn btn-warning btn-lg', 'title' => Yii::t('yii', $this->unpublishbtntxt), 'data-toggle' => 'modal', 'data-target' => '#' . $uppublishedmodal, 'data-remote' => Url::toRoute(['unpublish', 'id' => $this->model->id])]);
     }
     echo '&nbsp;&nbsp;';
     echo Html::resetButton('Reset', ['class' => 'btn btn-lg btn-default']);
     echo '&nbsp;&nbsp;';
     echo Html::resetButton('Back', ['class' => 'btn btn-lg btn-default', 'onclick' => 'history.go(-1);return true;']);
     echo "\n" . Html::endTag('div');
     foreach ($modal as $bs_modal) {
         echo Modal::widget($bs_modal);
     }
     $this->view->registerJs("\n                    var _frm = \$('.changeaction').first().closest('form');\n                    var _frmdata = null,alreadySubmitted = false;\n                    if(_frm != null && _frm !=undefined){\n                        _frmdata = _frm.serialize();\n                    }\n        ");
     $this->view->registerJs("\$('.changeaction').click(function(e) {\n                    e.preventDefault();\n                    if(typeof \$(this).attr('data-url') != 'undefined' && \$(this).attr('data-url') != ''){\n                        btnType = \$(this).text();\n                        frm = \$(this).parents('form');\n                        if(btnType == 'Publish'){\n                            if(_frmdata != null && _frmdata != frm.serialize()){\n                                alert('Please save changes before going to publish it');\n                                return false;\n                            }\n                        }\n                        if(alreadySubmitted === false){\n                            \$(this).parents('form').attr('action',\$(this).attr('data-url')).submit();\n                            aalreadySubmitted = true;\n                        }\n                    }\n                });");
 }
 /**
  * Renders the widget.
  */
 public function run()
 {
     $modal = [];
     if (\yii::$app->user->can('update')) {
         echo Html::a('Edit', ['update', 'id' => $this->model->Id], ['class' => 'btn btn-primary']);
     }
     if ($this->model->state != AppActiveRecord::STATUS_DRAFT) {
         //echo $this->model->state;
         if ($this->model->state != AppActiveRecord::STATUS_PUBLISH && \yii::$app->user->can('publish')) {
             echo '&nbsp;&nbsp;';
             echo Html::a('Publish', ['publish', 'id' => $this->model->Id], ['class' => 'btn btn-success', 'data-method' => 'post', 'title' => Yii::t('yii', 'Publish'), 'data-pjax' => '0']);
         } elseif ($this->model->state != AppActiveRecord::STATUS_PUBLISHREADY && $this->model->state != AppActiveRecord::STATUS_PUBLISH && \yii::$app->user->can('sendtopublish')) {
             echo '&nbsp;&nbsp;';
             echo Html::a('Send to Publisher', ['sendtopublish', 'id' => $this->model->Id], ['class' => 'btn btn-success', 'data-method' => 'post', 'title' => Yii::t('yii', 'Send to Publisher'), 'data-pjax' => '0']);
         }
         if ($this->unpublishbtn && $this->model->state == AppActiveRecord::STATUS_PUBLISH && \yii::$app->user->can('unpublish')) {
             echo '&nbsp;&nbsp;';
             $uppublishedmodal = 'modal-unpub';
             $modal[] = ['id' => $uppublishedmodal, 'header' => '<h4>Unpublish ' . strtolower($this->model->ClassSortNeme()) . ': ' . $this->model->name . '</h4>'];
             echo Html::button($this->unpublishbtntxt, ['class' => 'btn btn-warning', 'title' => Yii::t('yii', $this->unpublishbtntxt), 'data-toggle' => 'modal', 'data-target' => '#' . $uppublishedmodal, 'data-remote' => Url::toRoute(['unpublish', 'id' => $this->model->Id])]);
         }
         if ($this->closebtn && $this->model->state == AppActiveRecord::STATUS_PUBLISH && $this->model->status == AppActiveRecord::STATUS_PUBLISH && \yii::$app->user->can('updatestatus')) {
             echo '&nbsp;&nbsp;';
             $uppublishedmodal = 'modal-updatestatus';
             $modal[] = ['id' => $uppublishedmodal, 'header' => '<h4>' . $this->closebtntxt . ' ' . strtolower($this->model->ClassSortNeme()) . ': ' . $this->model->name . '</h4>'];
             echo Html::button($this->closebtntxt, ['class' => 'btn btn-warning', 'title' => Yii::t('yii', $this->closebtntxt), 'data-toggle' => 'modal', 'data-target' => '#' . $uppublishedmodal, 'data-remote' => Url::toRoute(['updatestatus', 'id' => $this->model->Id])]);
         }
         if ($this->deletebtn && \yii::$app->user->can('delete')) {
             echo '&nbsp;&nbsp;';
             /*
                             echo Html::a('Delete', ['delete', 'id' =>$this->model->Id], [
                                 'class' => 'btn btn-danger',
                                 'data' => [
                                     'confirm' => 'Are you sure you want to delete this item?',
                                     'method' => 'post',
                                 ],
                             ]);
                             //*/
             $deletemodal = 'modal-trash';
             $modal[] = ['id' => $deletemodal, 'header' => '<h4>Delete ' . strtolower($this->model->ClassSortNeme()) . ': ' . $this->model->name . '</h4>'];
             echo Html::button($this->deletebtntxt, ['class' => 'btn btn-danger', 'title' => Yii::t('yii', 'Unpublish'), 'data-toggle' => 'modal', 'data-target' => '#' . $deletemodal, 'data-remote' => Url::toRoute(['delete', 'id' => $this->model->Id])]);
         }
     } else {
         echo '&nbsp;&nbsp;';
         echo Html::a('Delete', ['delete', 'id' => $this->model->Id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]);
     }
     echo '&nbsp;&nbsp;';
     echo Html::button('Back', ['class' => 'btn btn-default', 'onclick' => 'history.go(-1);return true;']);
     echo "\n" . Html::endTag('div');
     foreach ($modal as $bs_modal) {
         echo Modal::widget($bs_modal);
     }
 }