Commit b0acfdc3 authored by Alina Habibulina's avatar Alina Habibulina

+ time period

parent 2aaa9b5a
...@@ -81,6 +81,13 @@ var portal = { ...@@ -81,6 +81,13 @@ var portal = {
createPlayer : function(){ createPlayer : function(){
portal.clearPlayer(); portal.clearPlayer();
portal.player = AS.FORMS.createPlayer(); portal.player = AS.FORMS.createPlayer();
AS.FORMS.bus.on(AS.FORMS.EVENT_TYPE.formShow, function (event, model, view) {
if (model.formCode === "timesheet") {
model.on(AS.FORMS.EVENT_TYPE.dataLoad, function() {
portal.main(portal.player.view.getViewWithId("main_script"), portal.player.model.getModelWithId("main_script"));
});
}
});
AS.FORMS.ApiUtils.simpleAsyncGet('rest/api/registry/create_doc?registryCode=registry_timesheets', function(result){ AS.FORMS.ApiUtils.simpleAsyncGet('rest/api/registry/create_doc?registryCode=registry_timesheets', function(result){
if(result.errorCode != "0") { if(result.errorCode != "0") {
AS.SERVICES.hideWaitWindow(); AS.SERVICES.hideWaitWindow();
...@@ -92,7 +99,9 @@ var portal = { ...@@ -92,7 +99,9 @@ var portal = {
portal.player.view.setEditable(true); portal.player.view.setEditable(true);
portal.player.showFormData(result.documentID, 0, result.dataUUID); portal.player.showFormData(result.documentID, 0, result.dataUUID);
portal.player.view.appendTo($('#form_player_div')); portal.player.view.appendTo($('#form_player_div'));
}}, 'json'); }
}, 'json');
}, },
saveData : function(){ saveData : function(){
...@@ -113,9 +122,89 @@ var portal = { ...@@ -113,9 +122,89 @@ var portal = {
ShowMessage("Данные сохранены"); ShowMessage("Данные сохранены");
} }
}); });
},
main: function (view, model) {
var serverDateTime = portal.player.model.getModelWithId("ts_date_created").value;
var serverDate = serverDateTime.substr(0, serverDateTime.length - 9);
var serverWeekDay = new Date(serverDate).getDay();
switch(serverWeekDay){
case 0:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 7)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, 1)); // 1й день пндк нашей недели
break;
case 1:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 6)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, 0)); // 1й день пндк нашей недели
break;
case 2:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 5)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-1))); // 1й день пндк нашей недели
break;
case 3:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 4)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-2))); // 1й день пндк нашей недели
break;
case 4:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 3)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-3))); // 1й день пндк нашей недели
break;
case 5:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 2)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-4))); // 1й день пндк нашей недели
break;
case 6:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 1)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-5))); // 1й день пндк нашей недели
break;
case 7:
portal.player.model.getModelWithId("ts_period_date_to").setValue(WeekCalculating(serverDate, 0)); //0 день воскресение прошлой недели
portal.player.model.getModelWithId("ts_period_date_from").setValue(WeekCalculating(serverDate, (-6))); // 1й день пндк нашей недели
break;
}
function WeekCalculating(fullDate, shift){
var year = fullDate.substr(0, (fullDate.length - 6));
var month = fullDate.substr(5, (fullDate.length));
month = month.substr(0, (month.length - 3));
var day = fullDate.substr(8, fullDate.length);
day = parseInt(day) + shift;
switch(month){
case "01":
case "03":
case "05":
case "07":
case "08":
case "10":
case "12":
if(parseInt(day) > 31) { month = parseInt(month) + 1; day = "01";}
break;
case "04":
case "06":
case "09":
case "11":
if(parseInt(day) > 30) { month = parseInt(month) + 1; day = "01";}
break;
case "02":
if((parseInt(year)%4 == 0) || (parseInt(year)%400 == 0)) {
if(parseInt(day) > 29) { month = parseInt(month) + 1; day = "01";}
} else {
if(parseInt(day) > 28) { month = parseInt(month) + 1; day = "01";}
}
break;
}
if((parseInt(month) + shift) > 12) { month = "01"; year = year + 1; } /////если месяцев больше 12, то увелививаем год
if(parseInt(day) < 10) day = "0" + day;
var finalDate = year + "-" + month + "-" + day;
return finalDate;
}
} }
}; };
//переменные для WaitCircles(); //переменные для WaitCircles();
var currentTime = Date.now(), var currentTime = Date.now(),
r = 40, r = 40,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment