/**
  * Renders the widget.
  */
 public function run()
 {
     //echo $this->model->state;
     //for new record creation
     if ($this->model->isNewRecord || $this->model->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 && $this->model->state != AppActiveRecord::STATUS_DRAFT && ($this->model->state != AppActiveRecord::STATUS_PUBLISH || $this->model->state != AppActiveRecord::STATUS_PUBLISHREADY)) {
         if ($this->model->state != AppActiveRecord::STATUS_PUBLISH && \yii::$app->user->can('publish')) {
             echo '  ';
             echo Html::submitButton('Publish', ['class' => 'btn btn-lg changeaction btn-success aftervalidate', 'data-url' => Url::toRoute(array_merge(['publish'], $this->params))]);
         } elseif ($this->model->state != AppActiveRecord::STATUS_PUBLISHREADY && $this->model->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))]);
         }
     }
     /*
             echo '  ';
             AjaxSubmitButton::begin([
                 'label' => 'Validate',
                 'options' => [
                     'class' => 'btn btn-lg btn-primary',
                     'type'  => 'submit',
                 ],
                 'ajaxOptions' => [
                     'type'  =>'POST',
                     'url'   => Url::toRoute(array_merge(['validate'],$this->params)),
                     'success' => new \yii\web\JsExpression('function(data){
                         $("#errorwarning").html(data.html);
                         if(data.status){
                             $(".aftervalidate").removeClass("disabled");
                         }
                      }'),
                 ],
             ]);
             AjaxSubmitButton::end();
             //*/
     echo '  ';
     echo Html::resetButton('Reset', ['class' => 'btn btn-lg btn-default']);
     echo '  ';
     echo Html::resetButton('Back', ['class' => 'btn btn-lg btn-default', 'onclick' => 'history.go(-1);return true;']);
     echo "\n" . Html::endTag('div');
     $this->view->registerJs("\$('.changeaction').click(function() {\n                    if(typeof \$(this).attr('data-url') != 'undefined' && \$(this).attr('data-url') != ''){\n                        \$(this).parents('form').attr('action',\$(this).attr('data-url')).submit();\n                    }\n                });");
 }
 /**
  * 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                });");
 }
Example #3
0
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>
    <p>
        <?php 
echo Html::beginForm('', 'post', ['class' => 'uk-width-medium-1-1 uk-form uk-form-horizontal']);
?>
        <?php 
echo Select2::widget(['name' => 'country_code', 'data' => Organisations::dropdown(), 'options' => ['id' => 'country_select', 'multiple' => false, 'placeholder' => 'Choose...', 'class' => 'uk-width-medium-7-10']]);
?>
        <?php 
AjaxSubmitButton::begin(['label' => 'Refresh', 'ajaxOptions' => ['type' => 'POST', 'url' => 'index.php?r=organisations/refreshdata1', 'success' => new \yii\web\JsExpression('function(html){
                  $("#output").html(html);
                  }')], 'options' => ['class' => 'btn btn-primary', 'type' => 'submit']]);
AjaxSubmitButton::end();
?>
        <?php 
echo Html::endForm();
?>
    </p>
    <div id="output"></div>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'uid', 'label', 'abbreviation', 'category', 'website', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>