TRI-293: edit form
This commit is contained in:
@@ -1,11 +1,38 @@
|
||||
!function () {
|
||||
'use strict';
|
||||
var posterApp = {
|
||||
locale_ru: new Object({
|
||||
direction: "ltr",
|
||||
format: "DD.MM.YYYY",
|
||||
separator: " - ",
|
||||
applyLabel: "Принять",
|
||||
cancelLabel: "Отменить",
|
||||
weekLabel: "Н",
|
||||
customRangeLabel: "Custom Range",
|
||||
|
||||
}),
|
||||
|
||||
locale_en: new Object({
|
||||
direction: "ltr",
|
||||
format: "DD.MM.YYYY",
|
||||
separator: " - ",
|
||||
applyLabel: "Apply",
|
||||
cancelLabel: "Cancel",
|
||||
weekLabel: "W",
|
||||
customRangeLabel: "Custom Range",
|
||||
|
||||
}),
|
||||
|
||||
changeLangForDateTimePicker: function () {
|
||||
moment.locale(document.documentElement.lang === 'ru' ? 'ru' : 'en');
|
||||
return document.documentElement.lang === 'ru' ? this.locale_ru : this.locale_en
|
||||
},
|
||||
|
||||
|
||||
// todo определение фоормата даты можно вынести на бэк для контроля
|
||||
initDatePickerr: function () {
|
||||
const _this = this;
|
||||
[this._selector.inpDeparture, this._selector.inpArrival].forEach(i => {
|
||||
if(!i.length) return
|
||||
if (!i.length) return
|
||||
let date = i.val().trim() ? i.val() : new Date();
|
||||
let startDate = null
|
||||
if (window.location.href.includes("/ru/")) {
|
||||
@@ -21,7 +48,7 @@
|
||||
"timePicker": false,
|
||||
"timePicker24Hour": false,
|
||||
"minDate": startDate,
|
||||
"locale": changeLangForDateTimePicker(),
|
||||
"locale": _this.changeLangForDateTimePicker(),
|
||||
}, function (start, end, label) {
|
||||
i.val(start.format('DD.MM.YYYY'));
|
||||
});
|
||||
@@ -42,31 +69,28 @@
|
||||
},
|
||||
|
||||
|
||||
changeCargoType: function () {
|
||||
changeDisabledType: function () {
|
||||
let inpTypeAvia = this._selector.typeItems.filter((d, i) => i.value === 'avia');
|
||||
let inpTypePassenger = this._selector.cargoItems.filter((d, i) => i.value === 'passenger');
|
||||
this._selector.cargoItems.off('change.i-disable').on('change.i-disable', (e) => {
|
||||
this.handlerDisabled(e.target, inpTypeAvia, 'passenger')
|
||||
})
|
||||
this.handlerDisabled($(e.target).val(), inpTypeAvia, 'passenger')
|
||||
});
|
||||
this._selector.typeItems.off('change.i-disable2').on('change.i-disable2', (e) => {
|
||||
this.handlerDisabled($(e.target).val(), inpTypePassenger, 'avia')
|
||||
});
|
||||
// change other type
|
||||
this.handlerDisabled(inpTypePassenger, inpTypeAvia, 'passenger')
|
||||
this.handlerDisabled(this.getDataForm(true).cargo_type, inpTypeAvia, 'passenger')
|
||||
this.handlerDisabled(this.getDataForm(true).type_transport, inpTypePassenger, 'avia')
|
||||
},
|
||||
|
||||
handlerDisabled: function (el, el2, text) {
|
||||
if ($(el).val() === text) {
|
||||
if (el === text) {
|
||||
$(el2).attr('disabled', true);
|
||||
} else {
|
||||
$(el2).attr('disabled', false);
|
||||
}
|
||||
},
|
||||
|
||||
changeTransportType: function () {
|
||||
let inpTypePassenger = this._selector.cargoItems.filter((d, i) => i.value === 'passenger');
|
||||
this._selector.typeItems.off('change.i-disable').on('change.i-disable', (e) => {
|
||||
this.handlerDisabled(e.target, inpTypePassenger, 'avia');
|
||||
})
|
||||
},
|
||||
|
||||
createInpCoutryData: function (el, data) {
|
||||
el.dataCoutry?.remove();
|
||||
let template =
|
||||
@@ -148,12 +172,11 @@
|
||||
|
||||
validForm: function () {
|
||||
let elems = this._selector.root[0].elements
|
||||
//todo пустые значения
|
||||
elems.departure_DT.value = elems.departure_DT.value.trim()
|
||||
if (!elems.departure_DT.value) {
|
||||
this._cl('!elems.departure_DT.value is empty set " "')
|
||||
elems.departure_DT.value = moment(new Date()).format(this._data.formatDate);
|
||||
}
|
||||
// console.log(elems.departure_DT.value.trim(), elems.departure_DT.value === '', elems.departure_DT.value, elems.departure_DT)
|
||||
},
|
||||
|
||||
initSubmit: function () {
|
||||
@@ -167,9 +190,7 @@
|
||||
if (routeId) {
|
||||
url = '/routes/change_route/' + routeId + '/'
|
||||
}
|
||||
|
||||
if (_this.getDataForm(true))
|
||||
console.log(_this.getDataForm(true))
|
||||
_this._cl(_this.getDataForm(true))
|
||||
$.ajax({
|
||||
headers: {"X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val()},
|
||||
url: url,
|
||||
@@ -179,39 +200,20 @@
|
||||
contentType: false,
|
||||
data: formData,
|
||||
success: function (data) {
|
||||
// return
|
||||
let data_route_id = data.route_id
|
||||
document.querySelector(".info_profile").innerHTML = data.html
|
||||
|
||||
let el_route = document.querySelector(`[data-number-of-route="${data_route_id}"]`);
|
||||
if (routeId) {
|
||||
el_route = document.querySelector(`[data-number-of-route="${routeId}"]`);
|
||||
}
|
||||
if (el_route) {
|
||||
el_route.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: 'start',
|
||||
inline: 'start'
|
||||
});
|
||||
}
|
||||
let currentUrl = window.location.pathname;
|
||||
let newUrl = '';
|
||||
|
||||
if (currentUrl.includes('/create_route_for_customer')) {
|
||||
newUrl = currentUrl.replace('/create_route_for_customer', '/my_routes');
|
||||
} else if (currentUrl.includes('/create_route_for_mover')) {
|
||||
newUrl = currentUrl.replace('/create_route_for_mover', '/my_routes');
|
||||
}
|
||||
window.history.replaceState(null, '', newUrl);
|
||||
_this._selector.wrapper.html(data.html);
|
||||
_this._cl('data success',data)
|
||||
window.location.assign(location.pathname.split('/').slice(0,-2).join('/') + '/my_routes')
|
||||
},
|
||||
error: function (data, exception) {
|
||||
console.log(data)
|
||||
document.querySelector(".info_profile").innerHTML = data.responseJSON.html;
|
||||
document.getElementById('departure_DT')?.scrollIntoView({
|
||||
_this._cl('is-error data', data)
|
||||
_this._selector.wrapper.html(data.responseJSON.html);
|
||||
setTimeout(()=>{
|
||||
$('.errorlist>li').parents('.poster__row')[0]?.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: 'nearest',
|
||||
inline: 'nearest'
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -235,7 +237,7 @@
|
||||
data: JSON.stringify(getTownData),
|
||||
success: function (data) {
|
||||
el.removeClass('loading');
|
||||
const {res_search_list, unanswered_msgs_count} = data;
|
||||
const {res_search_list} = data;
|
||||
_this.setDataTowns(data, el)
|
||||
_this.initHandlerItemsTowns(el)
|
||||
_this.handlerShowList(el)
|
||||
@@ -248,7 +250,7 @@
|
||||
el.removeClass('is-items')
|
||||
el.list.removeClass('is-items')
|
||||
}
|
||||
console.log('fetch', data)
|
||||
_this._cl('fetch', data)
|
||||
},
|
||||
error: function (data) {
|
||||
|
||||
@@ -261,20 +263,19 @@
|
||||
handlerSearchTown: function (e, i) {
|
||||
this._cl('handlerSearchTown');
|
||||
let el = i;
|
||||
console.log('out', el.prevValue, el.val())
|
||||
this._cl('handlerSearchTown el prV - elV', [el.prevValue, el.val()])
|
||||
if (el.prevValue && el.val().length < el.prevValue.length) {
|
||||
// clean input
|
||||
el.parent().removeClass('is-set')
|
||||
el.next('.poster__inp-country').remove()
|
||||
console.log(el, `${el[0].name.split('_')[0]}_city`, this._selector.root[0].elements[`${el[0].name.split('_')[0]}_city`])
|
||||
this._cl('', [el, `${el[0].name.split('_')[0]}_city`, this._selector.root[0].elements[`${el[0].name.split('_')[0]}_city`]])
|
||||
this._selector.root[0].elements[`${el[0].name.split('_')[0]}_city`].value = ''
|
||||
el.val('');
|
||||
}
|
||||
|
||||
if (el.val().length > 2) {
|
||||
console.log('in')
|
||||
|
||||
this._cl('in')
|
||||
el.addClass('loading');
|
||||
|
||||
clearTimeout(el.timer)
|
||||
el.timer = setTimeout(() => {
|
||||
this.getTowns(el);
|
||||
@@ -309,6 +310,7 @@
|
||||
|
||||
initData: function (root) {
|
||||
window.posterApp = this;
|
||||
window.mobileWidth = 768;
|
||||
this._data = {
|
||||
debug: true,
|
||||
formatDate: 'DD.MM.YYYY',
|
||||
@@ -328,7 +330,7 @@
|
||||
typeItems: root.find('.cargo__inp[name="type_transport"]'),
|
||||
inpDeparture: root.find('#departure_DT'),
|
||||
inpArrival: root.find('#arrival_DT'),
|
||||
submitBtn: root.find('button')
|
||||
submitBtn: root.find('button'),
|
||||
};
|
||||
this._selector.inpFrom.list = this._selector.inpFromList
|
||||
this._selector.inpFrom.date = this._selector.inpDeparture
|
||||
@@ -346,8 +348,7 @@
|
||||
this.initHandlerRoute();
|
||||
this.initDatePickerr();
|
||||
this.initSubmit();
|
||||
this.changeCargoType();
|
||||
this.changeTransportType();
|
||||
this.changeDisabledType();
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -144,11 +144,11 @@ function getTypeOfData (data) {
|
||||
|
||||
function getInfoAboutUser (screen_width){
|
||||
let user_type = ''
|
||||
if (screen.width <= 700){
|
||||
if (screen.width <= (window.mobileWidth || 700)){
|
||||
user_type = 'mobile'
|
||||
} else if (screen.width > 1180) {
|
||||
user_type = 'desctop'
|
||||
} else if (screen.width > 700 && screen.width <= 1180) {
|
||||
} else if (screen.width > (window.mobileWidth || 700) && screen.width <= 1180) {
|
||||
user_type = 'laptop'
|
||||
}
|
||||
if (screen_width){
|
||||
|
||||
Reference in New Issue
Block a user