namespace yii_app\controllers\crud;
+use Yii;
+use yii\helpers\ArrayHelper;
use yii_app\records\MarketplaceOrder1cStatuses;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
+use yii_app\services\LessonService;
/**
* MarketplaceOrder1cStatusesController implements the CRUD actions for MarketplaceOrder1cStatuses model.
parent::behaviors(),
[
'verbs' => [
- 'class' => VerbFilter::className(),
+ 'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
*
* @return string
*/
- public function actionIndex()
- {
+ public function actionIndex() {
+ if (Yii::$app->request->isPost) {
+ $action = Yii::$app->request->post('action');
+ if ($action == 'sorting') {
+ $oldIndex = Yii::$app->request->post('oldIndex');
+ $newIndex = Yii::$app->request->post('newIndex');
+
+ $mo1s = MarketplaceOrder1cStatuses::find()->orderBy(['posit' => SORT_ASC])->all();
+ LessonService::movePosition($mo1s, $oldIndex, $newIndex, 'posit');
+
+ return $oldIndex . ' ' . $newIndex;
+ } else {
+ $this->response->format = \yii\web\Response::FORMAT_JSON;
+ return $this->asJson(MarketplaceOrder1cStatuses::find()->orderBy(['posit' => SORT_ASC])->asArray()->all());
+ }
+ }
+
$dataProvider = new ActiveDataProvider([
- 'query' => MarketplaceOrder1cStatuses::find(),
+ 'query' => MarketplaceOrder1cStatuses::find()->orderBy(["posit" => SORT_ASC]),
/*
'pagination' => [
'pageSize' => 50
'marketplace_id' => $this->integer()->notNull()->comment('Маркетплейс'),
'status' => $this->string(100)->notNull()->comment('Статус'),
'status_instruction' => $this->text()->notNull()->comment('Инструкция к статусу'),
+ 'posit' => $this->integer()->notNull()->defaultValue(0)->comment('Порядок статусов'),
]);
-// $this->batchInsert(self::TABLE_NAME, ['marketplace_id', 'status', 'status_instruction'], [
-//
-// ]);
+ $this->batchInsert(self::TABLE_NAME, ['marketplace_id', 'status', 'status_instruction', 'posit'], [
+ [1, 'Новый', '', 1],
+ [1, 'Правки флориста', '', 2],
+ [1, 'В работе', '', 3],
+ [1, 'Собрано', '', 4],
+ [1, 'Передано курьеру', '', 5],
+ [1, 'Успех', '', 6],
+ [1, 'Отказ', '', 7],
+ [2, 'Новый', '', 7 + 1],
+ [2, 'Правки флориста', '', 7 + 2],
+ [2, 'В работе', '', 7 + 3],
+ [2, 'Собрано', '', 7 + 4],
+ [2, 'Передано курьеру', '', 7 + 5],
+ [2, 'Успех', '', 7 + 6],
+ [2, 'Отказ', '', 7 + 7],
+ ]);
}
}
* @property int $marketplace_id Маркетплейс
* @property string $status Статус
* @property string $status_instruction Инструкция к статусу
+ * @property int $posit Порядок статусов
*/
class MarketplaceOrder1cStatuses extends \yii\db\ActiveRecord
{
return [
[['marketplace_id', 'status', 'status_instruction'], 'required'],
[['marketplace_id'], 'default', 'value' => null],
- [['marketplace_id'], 'integer'],
+ [['posit'], 'default', 'value' => 0],
+ [['marketplace_id', 'posit'], 'integer'],
[['status_instruction'], 'string'],
[['status'], 'string', 'max' => 100],
];
'marketplace_id' => 'Маркетплейс ID',
'status' => 'Статус',
'status_instruction' => 'Инструкция к статусу',
+ 'posit' => 'Порядок статусов',
];
}
}
/** @var yii\web\View $this */
/** @var yii\data\ActiveDataProvider $dataProvider */
+$this->registerCssFile('/css/customSortable.css');
+$this->registerJsFile('/js/Sortable.js', ['position' => \yii\web\View::POS_END]);
+$this->registerJsFile('/js/crud/marketplace-order1c-statuses/index.js', ['position' => \yii\web\View::POS_END]);
+
$this->title = 'Маркетплейс статусы заказа';
$this->params['breadcrumbs'][] = $this->title;
?>
<p>
<?= Html::a('Создать Маркетплейс Статус Заказа', ['create'], ['class' => 'btn btn-success']) ?>
+ <?= Html::button('Сортировка статусов заказа', ['class' => 'btn btn-secondary', 'onclick' => 'showSortingDialog()']) ?>
</p>
--- /dev/null
+/* jshint esversion: 6 */
+
+const param31 = $('meta[name=csrf-param]').attr("content");
+const token31 = $('meta[name=csrf-token]').attr("content");
+
+function showSortingDialog() {
+ $.ajax({
+ method : "POST",
+ url : window.location.href,
+ data : {[param31] : token31},
+ dataType : "json",
+ success: function (data) {
+ const $mainModal = $('#mainModal');
+ const $modalBody = $mainModal.find('.modal-body');
+ const $modalFooter = $mainModal.find('.modal-footer');
+ $mainModal.find('.close').on('click', () => { $mainModal.modal('hide'); });
+ $mainModal.find('.modal-title').html('Сортировка статусов');
+ $modalFooter.html('<button class="btn btn-success">ОК</button>');
+ const $saveButton = $modalFooter.find('button');
+ $saveButton.on('click', () => { $mainModal.modal('hide'); })
+
+ let tbody = '';
+ $.each(data, (ind, el) => {
+ tbody += '<div style="display:flex; justify-content: flex-start; align-items: stretch; margin-top: 0.2rem;">' +
+ ' <div class="drag-handler" style="width: 1rem;"></div>' +
+ ' <div>' +
+ {1 : "ФлауВау", 2 : "ЯндексМаркет"}[el.marketplace_id] + ' : ' + el.status +
+ ' </div>' +
+ '</div>'
+ })
+
+ $modalBody.html('<div class="draganddropTable">' + tbody + '</div>');
+
+ $mainModal.modal('show');
+
+ var $tableBody = $(".draganddropTable");
+
+ $tableBody.each(function () {
+ Sortable.create(
+ this,
+ {
+ animation: 250,
+ scroll: true,
+ handle: ".drag-handler",
+ onEnd: function (e) {
+ const name = $(e.from).data('name');
+ const oldIndex = e.oldIndex;
+ const newIndex = e.newIndex;
+ $.post(window.location.href, {
+ action: 'sorting',
+ name : name,
+ oldIndex : oldIndex,
+ newIndex : newIndex,
+ [param31] : token31
+ },
+ function (data) {
+ console.log(data);
+ });
+ }
+ }
+ );
+ });
+
+ }
+ });
+}
\ No newline at end of file