Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions local/js/otus/ctimeman/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();


return [
'js' => './src/script.js',
'css' => './src/style.css',
'rel' => [
'main.core', // Требуется для BX.create, BX.PreventDefault, BX.message
'main.popup', // Требуется для BX.PopupWindow
'ui.buttons', // Для стилей кнопок ui-btn
],
'lang' => './lang/ru/script.php', // Файл локализации
'skip_core' => false, // Не пропускать ядро Bitrix
];
17 changes: 17 additions & 0 deletions local/js/otus/ctimeman/lang/ru/script.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Файл локализации расширения otus.ctimeman
* Язык: Русский
*/

$MESS['OTUS_TIMEMAN_OPEN_DAY_TITLE'] = 'Начать рабочий день?';
$MESS['OTUS_TIMEMAN_OPEN_DAY_MESSAGE'] = 'Вы действительно хотите начать рабочий день?';

$MESS['OTUS_TIMEMAN_REOPEN_DAY_TITLE'] = 'Продолжить рабочий день?';
$MESS['OTUS_TIMEMAN_REOPEN_DAY_MESSAGE'] = 'Вы действительно хотите продолжить рабочий день?';

$MESS['OTUS_TIMEMAN_CLOSE_DAY_TITLE'] = 'Завершить рабочий день?';
$MESS['OTUS_TIMEMAN_CLOSE_DAY_MESSAGE'] = 'Вы действительно хотите завершить рабочий день?';

$MESS['OTUS_TIMEMAN_BUTTON_YES'] = 'Да';
$MESS['OTUS_TIMEMAN_BUTTON_CANCEL'] = 'Отмена';
179 changes: 179 additions & 0 deletions local/js/otus/ctimeman/src/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
BX.ready(function () {

'use strict';

//onAjaxSuccessFinish

//onPullEvent-timeman


const Messages = {
OPEN_DAY_TITLE: BX.message('OTUS_TIMEMAN_OPEN_DAY_TITLE') || 'Начать рабочий день?',
OPEN_DAY_MESSAGE: BX.message('OTUS_TIMEMAN_OPEN_DAY_MESSAGE') || 'Вы действительно хотите начать рабочий день?',
REOPEN_DAY_TITLE: BX.message('OTUS_TIMEMAN_REOPEN_DAY_TITLE') || 'Продолжить рабочий день?',
REOPEN_DAY_MESSAGE: BX.message('OTUS_TIMEMAN_REOPEN_DAY_MESSAGE') || 'Вы действительно хотите продолжить рабочий день?',
CLOSE_DAY_TITLE: BX.message('OTUS_TIMEMAN_CLOSE_DAY_TITLE') || 'Завершить рабочий день?',
CLOSE_DAY_MESSAGE: BX.message('OTUS_TIMEMAN_CLOSE_DAY_MESSAGE') || 'Вы действительно хотите завершить рабочий день?',
BUTTON_YES: BX.message('OTUS_TIMEMAN_BUTTON_YES') || 'Да',
BUTTON_CANCEL: BX.message('OTUS_TIMEMAN_BUTTON_CANCEL') || 'Отмена'
};

let status = '';
let confirmationPopup = null;


function showConfirmationDialog(title, message, onConfirm, onCancel) {

try {

confirmationPopup = new BX.PopupWindow("timeManConfirmation", null, {
content: message,
closeIcon: {right: "20px", top: "10px"},
titleBar: {content: BX.create("span", {html: title, 'props': {'className': 'otus-time-man-confirmation_title'}})},
zIndex: 0,
offsetLeft: 0,
offsetTop: 0,
draggable: {restrict: false},
overlay: {
backgroundColor: 'black',
opacity: 50
},
closeByEsc: true,
className: 'otus-time-man-confirmation',
buttons: [
new BX.PopupWindowButton({
text: Messages.BUTTON_YES,
className: "popup-window-button-accept",
events: {
click: function(){

if (typeof onConfirm === 'function') {
onConfirm();
}

//button.click();
this.popupWindow.close();
}
}
}),
new BX.PopupWindowButton({
text: Messages.BUTTON_CANCEL,
className: "webform-button-link-cancel",
events: {
click: function(){

this.popupWindow.close();

if (typeof onCancel === 'function') {
onCancel();
}
}
}
})
]
});

confirmationPopup.show();

} catch (error) {


}

}


BX.addCustomEvent('onTimeManDataRecieved', function(e) {
status = e.STATE;
//PAUSED
//CLOSED
});


BX.addCustomEvent('onTaskTimerChange', function() {


if(status === 'PAUSED' || status === 'CLOSED'){

setTimeout(function () {


const button = document.querySelector('#popup-window-content-bx-avatar-header-popup .tm-control-panel .tm-control-panel__actions-item button');


const copyButton = button.cloneNode(true);
const parent = button.parentNode;

button.style.display = 'none';
parent.appendChild(copyButton);

let title = status === 'CLOSED' ? Messages.OPEN_DAY_TITLE : Messages.REOPEN_DAY_TITLE;
let message = status === 'CLOSED' ? Messages.OPEN_DAY_MESSAGE : Messages.REOPEN_DAY_MESSAGE;

copyButton.addEventListener('click', function(e){
e.preventDefault();
showConfirmationDialog(
title,
message,
function(){
button.click();
},
false
)
});


}, 200);

}



/*button.addEventListener('click', function (e){
e.preventDefault();
e.stopPropagation();
alert(21212);
});*/



});



BX.addCustomEvent('onPullEvent-timeman', function(e) {

console.log('event: ');
console.log(e);

if(e === 'pause'){
const button = document.querySelector('#popup-window-content-bx-avatar-header-popup .tm-control-panel .tm-control-panel__actions-item button');


const copyButton = button.cloneNode(true);
const parent = button.parentNode;

button.style.display = 'none';
parent.appendChild(copyButton);

let title = Messages.REOPEN_DAY_TITLE;
let message = Messages.REOPEN_DAY_MESSAGE;

copyButton.addEventListener('click', function(e){
e.preventDefault();
showConfirmationDialog(
title,
message,
function(){
button.click();
},
false
)
});
}


})


});
7 changes: 7 additions & 0 deletions local/js/otus/ctimeman/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.otus-time-man-confirmation_title {
text-align: center;
display: block;
padding-top: 20px;
font-weight: bold;
font-size: 16px;
}
6 changes: 6 additions & 0 deletions local/php_interface/include/classes/Otus/Event/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Otus\Event;

use Bitrix\Main\Context;
use Bitrix\Main\UI\Extension;
use Otus\Debug\HistoryPage;

class Main
Expand All @@ -18,4 +19,9 @@ public static function handlerPageStart()
HistoryPage::add();
}
}

public static function OnProlog():void
{
Extension::load('otus.ctimeman');
}
}
8 changes: 8 additions & 0 deletions local/php_interface/include/events.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
use Otus\Event\Main;

$eventManager = \Bitrix\Main\EventManager::getInstance();

$eventManager->addEventHandlerCompatible('main', 'OnPageStart', '\Otus\Event\Main::handlerPageStart');
Expand All @@ -10,4 +12,10 @@
'Otus\UserType\OnlineRecord',
'GetUserTypeDescription'
]
);

$eventManager->addEventHandler(
'main',
'OnProlog',
[Main::class, 'OnProlog']
);