Skip to content

Commit

Permalink
big update
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Jun 4, 2022
1 parent b3d7a46 commit e2fbf4a
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 22 deletions.
16 changes: 12 additions & 4 deletions src/actions/BackendModelCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function init()
if (!$this->name) {
$this->name = \Yii::t('skeeks/backend', "Add");
}

if (!$this->successMessage) {
$this->successMessage = "" . \Yii::t('skeeks/cms', 'Saved');
}

parent::init();
}
Expand Down Expand Up @@ -141,10 +145,6 @@ public function run()

$this->trigger(self::EVENT_AFTER_SAVE);

if (!$this->successMessage) {
$this->successMessage = \Yii::t('skeeks/cms', 'Saved');
}

\Yii::$app->getSession()->setFlash('success', $this->successMessage);
$is_saved = true;

Expand All @@ -153,8 +153,16 @@ public function run()
$this->controller->model = $model;

if ($this->controller->modelActions) {
/**
* @var $action BackendModelAction
*/
if ($action = ArrayHelper::getValue($this->controller->modelActions,
$this->controller->modelDefaultAction)) {

/*$action->urlData = ArrayHelper::merge($action->urlData, [
'is_created' => 1
]);*/

$url = $action->url;
}
}
Expand Down
19 changes: 9 additions & 10 deletions src/actions/BackendModelUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use yii\base\DynamicModel;
use yii\base\Exception;
use yii\helpers\Url;
use yii\widgets\ActiveForm;

/**
* @property IBackendModelController|IHasUrl|IHasModel $controller
Expand Down Expand Up @@ -50,10 +49,14 @@ public function init()
$this->name = \Yii::t('skeeks/backend', "Edit");
}

if (!$this->successMessage) {
$this->successMessage = "" . \Yii::t('skeeks/cms', 'Saved');
}

parent::init();
}


public function run()
{
$is_saved = false;
Expand Down Expand Up @@ -121,10 +124,6 @@ public function run()

$this->trigger(self::EVENT_AFTER_SAVE);

if (!$this->successMessage) {
$this->successMessage = \Yii::t('skeeks/cms', 'Saved');
}

$is_saved = true;
\Yii::$app->getSession()->setFlash('success', $this->successMessage);

Expand Down Expand Up @@ -158,9 +157,9 @@ public function run()
return $this->render('@skeeks/cms/backend/actions/views/model-update', [
'model' => $this->model,
'formModels' => $this->formModels,
'is_saved' => $is_saved,
'submitBtn' => \Yii::$app->request->post('submit-btn'),
'redirect' => $redirect,
'is_saved' => $is_saved,
'submitBtn' => \Yii::$app->request->post('submit-btn'),
'redirect' => $redirect,
]);
//return $this->render('@skeeks/cms/backend/actions/views/model-update');
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/THasActiveForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ trait THasActiveForm
*
* @var array
*/
public $buttons = ['apply', 'save'];
public $buttons = ['apply'];

/**
* @param array $config
Expand Down
17 changes: 15 additions & 2 deletions src/actions/views/model-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
</div>
<? endif; ?>


<?php $form = $action->beginActiveForm([
'enableAjaxValidation' => false,
'enableClientValidation' => false,
]); ?>


<? if ($is_saved && @$is_create) : ?>
<?php $this->registerJs(<<<JS
sx.Window.openerWidgetTriggerEvent('model-create', {
Expand All @@ -52,6 +52,7 @@
); ?>
<? endif; ?>


<?= $form->errorSummary($formModels); ?>

<? echo \Yii::createObject([
Expand All @@ -62,8 +63,20 @@
'fields' => $action->fields,
])->render(); ?>

<?= $form->buttonsStandart($model, $action->buttons); ?>

<?php $successMessage = ''; ?>
<?php if(@$is_create) : ?>

<?php else : ?>
<? if ($successMessageFlash = \Yii::$app->getSession()->getFlash('success')) : ?>
<?php $successMessage = $successMessageFlash; ?>
<? endif; ?>
<?php endif; ?>


<?= $form->buttonsStandart($model, $action->buttons, $successMessage); ?>
<?= $form->errorSummary($formModels); ?>

<?php $form::end(); ?>


Expand Down
5 changes: 3 additions & 2 deletions src/forms/TActiveFormHasButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ trait TActiveFormHasButtons
* @param array $buttons - param is deprecated
* @return string
*/
public function buttonsStandart(Model $model, $buttons = ['apply'])
public function buttonsStandart(Model $model, $buttons = ['apply'], $successMessage = '')
{
$widgetClass = $this->buttonsClass;

Expand All @@ -53,9 +53,10 @@ public function buttonsStandart(Model $model, $buttons = ['apply'])
} else {
$this->buttonsConfig['isClose'] = false;
}

$widgetConfig = ArrayHelper::merge($this->buttonsConfig, [
'activeForm' => $this,
'successMessage' => $successMessage,
'model' => $model,
]);

Expand Down
32 changes: 29 additions & 3 deletions src/widgets/FormButtonsBackendWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ class FormButtonsBackendWidget extends Widget
*/
public $activeForm = null;

/**
* @var null
*/
public $successMessage = null;

/**
* @var string
*/
public $template = "<span class='sx-save-btns-group'>{saveAndClose} {save}</span><span class='sx-prev-next-btns-group sx-btns-group'>{prevNext}</span><span class='sx-other-btns-group sx-btns-group'>{other}</span><span class='sx-close-btns-group sx-btns-group float-right'>{close}</span>";
public $template = "<span class='sx-save-btns-group'>{saveAndClose} {save}</span>
<span class='sx-prev-next-btns-group sx-btns-group'>{prevNext}</span>
<span class='sx-success-meessage'>{successMessage}</span>
<span class='sx-other-btns-group sx-btns-group'>{other}</span>
<span class='sx-close-btns-group sx-btns-group float-right'>{close}</span>";

/**
* @var string Дополнительные кнопки или контент
Expand Down Expand Up @@ -120,6 +129,10 @@ public function run()
$this->_renderOther();
}

if (!isset($this->parts['{successMessage}'])) {
$this->_renderSuccessMessage();
}

$content = strtr($this->template, $this->parts);
} elseif (!is_string($content)) {
$content = call_user_func($content, $this);
Expand Down Expand Up @@ -167,7 +180,7 @@ protected function _renderSaveAndClose()
$this->parts['{saveAndClose}'] = "";

if ($this->isSaveAndClose) {
$this->parts['{saveAndClose}'] = Html::submitButton("".\Yii::t('skeeks/backend', 'Save and close'), [
$this->parts['{saveAndClose}'] = Html::submitButton(\Yii::t('skeeks/backend', 'Save'), [
'title' => \Yii::t("skeeks/backend", "The result will be saved and the editing window will be closed")." (ctrl+↵)",
'class' => 'btn btn-primary sx-btn-save-and-close',
]);
Expand All @@ -194,7 +207,7 @@ protected function _renderSave()

if ($this->isSave) {

$this->parts['{save}'] = Html::submitButton("".\Yii::t('skeeks/backend', 'Save'), [
$this->parts['{save}'] = Html::submitButton(\Yii::t('skeeks/backend', 'Save'), [
'title' => \Yii::t('skeeks/backend', 'The result will be saved and you can further edit the data')." (ctrl+s)",
'class' => 'btn btn-primary sx-btn-save',
]);
Expand Down Expand Up @@ -245,6 +258,19 @@ protected function _renderPrevNext()
$this->parts['{prevNext}'] = $submit;
}

return $this;
}
/**
* @return $this
*/
protected function _renderSuccessMessage()
{
$this->parts['{successMessage}'] = "";

if ($this->successMessage) {
$this->parts['{successMessage}'] = $this->successMessage;
}

return $this;
}
}
6 changes: 6 additions & 0 deletions src/widgets/assets/src/css/form.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ form.sx-backend-form
margin-left: 30px;
}

form.sx-backend-form .sx-buttons-standart-wrapper .sx-success-meessage {
margin-left: 30px;
color: green;
font-weight: bold;
}

form.sx-backend-form .sx-buttons-standart
{
/*border-top: 1px solid #ddd;*/
Expand Down
8 changes: 8 additions & 0 deletions src/widgets/assets/src/js/form-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
},

_init: function () {
var self = this;

this.onBeforeUnload = false;

this.on("changeData", function() {
$(".sx-success-meessage", self.getJForm()).empty();
});
},

/**
Expand Down Expand Up @@ -133,10 +139,12 @@
//Отслеживание изменения данных в форме
$("input, select, textarea", this.getJForm()).on("change", function () {
self.getJForm().addClass("sx-form-data-changed");
self.trigger("changeData");
self._initCloseWindow();
});
$("input, select, textarea", this.getJForm()).on("keyup", function () {
self.getJForm().addClass("sx-form-data-changed");
self.trigger("changeData");
self._initCloseWindow();
});

Expand Down

0 comments on commit e2fbf4a

Please sign in to comment.