Przypomnij.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('Przypomnij');
  4. Lib::loadClass('TypespecialVariable');
  5. class Route_Przypomnij extends RouteBase {
  6. public $_model = null;
  7. public $_selectedLogin = null;
  8. public $_allowedUsers = null;
  9. public function handleAuth() {
  10. if (User::get('ADM_ADMIN_LEVEL') > 5) {
  11. SE_Layout::gora();
  12. SE_Layout::menu();
  13. ?>
  14. <div class="container">
  15. <div class="alert alert-danger">
  16. Brak dostępu!
  17. </div>
  18. </div>
  19. <?php
  20. SE_Layout::dol();
  21. exit;
  22. }
  23. if (!User::logged()) {
  24. //throw new HttpException('Unauthorized', 401);
  25. User::authByRequest();
  26. }
  27. }
  28. public function defaultAction() {
  29. SE_Layout::gora();
  30. SE_Layout::menu();
  31. try {
  32. $this->_initArgs();
  33. } catch (Exception $e) {
  34. echo '<div class="container">';
  35. SE_Layout::alert('danger', $e->getMessage());
  36. echo '</div>';
  37. }
  38. $this->menu();
  39. $this->printEvents();
  40. SE_Layout::dol();
  41. }
  42. public function _initArgs() {
  43. $this->getModel();
  44. $this->getAllowedLoginList();
  45. $this->getSelectedLogin();
  46. }
  47. public function getModel() {
  48. if (null === $this->_model) {
  49. $this->_model = new Przypomnij();
  50. $this->_model->setRecurseLimit(3);// TODO: 10
  51. }
  52. return $this->_model;
  53. }
  54. public function getAllowedLoginList() {
  55. if (null === $this->_allowedUsers) {
  56. $przypomnij = $this->getModel();
  57. $this->_allowedUsers = $przypomnij->getAllowedUsersList();
  58. }
  59. return $this->_allowedUsers;
  60. }
  61. public function getSelectedLogin() {
  62. if (null === $this->_selectedLogin) {
  63. $allowedLoginList = $this->getAllowedLoginList();
  64. $this->_selectedLogin = isset($_GET['KTO'])? $_GET['KTO'] : '';
  65. if (!empty($this->_selectedLogin)) {
  66. if (!array_key_exists($this->_selectedLogin, $allowedLoginList)) {
  67. $this->_selectedLogin = '';
  68. throw new Exception("Brak danych - wybierz innego użytkownika");
  69. }
  70. }
  71. }
  72. return $this->_selectedLogin;
  73. }
  74. public function menu() {
  75. $usrLogin = User::getLogin();
  76. $selectedLogin = $this->getSelectedLogin();
  77. $typeSpecialUserLogin = TypespecialVariable::getInstance(-1, '__USER_LOGIN');
  78. ?>
  79. <style type="text/css">
  80. #przypomnij-menu .typepsecial .selectize-input { width:260px; padding:6px 12px; vertical-align:middle; }
  81. </style>
  82. <div id="przypomnij-menu" class="container" style="margin-top:8px;">
  83. <form class="form-inline" role="search">
  84. <?php if(V::get('DBG_P', '', $_GET)){echo'<input type="hidden" name="DBG_P" value="1">';} ?>
  85. <input type="hidden" name="_route" value="Przypomnij">
  86. <div class="form-group">
  87. <?php
  88. if ($typeSpecialUserLogin) {
  89. $fldName = 'KTO';
  90. $fldParams = array();
  91. $fldParams['allowCreate'] = false;
  92. $fldParams['ajaxDataUrlBase'] = "index.php?_route=Przypomnij&_task=typeSpecialUserLogin";
  93. $fldParams['placeholder'] = 'Szukaj...';
  94. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  95. echo $typeSpecialUserLogin->showFormItem($tblID = -1, $fldName, $selectedLogin, $fldParams);
  96. } else {
  97. // TODO: simple select by allowedUsers
  98. }
  99. ?>
  100. </div>
  101. <button type="submit" class="btn btn-default">Pokaż</button>
  102. <div class="btn-group" style="margin-left:20px;">
  103. <a class="btn btn-link" href="index.php?_route=Przypomnij&KTO=<?php echo $usrLogin; ?>">Twoje (<?php echo $usrLogin; ?>)</a>
  104. </div>
  105. <div class="btn-group" style="margin-left:20px;">
  106. <a class="btn btn-link" href="index.php?_route=Przypomnij">Wszyscy</a>
  107. </div>
  108. </form>
  109. </div>
  110. <?php
  111. }
  112. public function typeSpecialUserLoginAction() {
  113. header("Content-type: application/json");
  114. $typeSpecialUserId = TypespecialVariable::getInstance(-1, '__USER_LOGIN');
  115. if (!$typeSpecialUserId) {
  116. $jsonData = new stdClass();
  117. $jsonData->message = "TypeSpecial '__USER_LOGIN' not exists";
  118. echo json_encode($jsonData);
  119. exit;
  120. }
  121. $query = V::get('q', '', $_REQUEST);
  122. $rawRows = null;
  123. $jsonData = array();
  124. $queryParams = array();
  125. $rows = $typeSpecialUserId->getValuesWithExports($query, $queryParams);
  126. foreach ($rows as $kID => $vItem) {
  127. $itemJson = new stdClass();
  128. $itemJson->id = $vItem->id;
  129. $itemJson->name = $vItem->param_out;
  130. if (!empty($vItem->exports)) {
  131. $itemJson->exports = $vItem->exports;
  132. }
  133. $jsonData[] = $itemJson;
  134. }
  135. echo json_encode($jsonData);
  136. }
  137. public function printEvents() {
  138. $selectedLogin = $this->getSelectedLogin();
  139. $przypomnij = $this->getModel();
  140. $przypomnij->fetchData();
  141. $przypomnij->setFltrUser($selectedLogin);
  142. $tasks = $przypomnij->getTasksByDate();
  143. DBG::_('DBG_P', true, "tasks", $tasks, __CLASS__, __FUNCTION__, __LINE__);
  144. $usrGroupNames = User::getLdapGroupsNames();
  145. foreach ($tasks as $id => $task) {
  146. $tasks[$id]->_visible = true;
  147. //@2015-05-17 - ograniczenie widzenia listy przypomnij dla obcych uzystkownikow,
  148. if (
  149. $task->A_CLASSIFIED != ''
  150. and !(in_array($task->A_CLASSIFIED, $usrGroupNames))
  151. and $task->A_ADM_COMPANY != ''
  152. and !(in_array($task->A_ADM_COMPANY, $usrGroupNames))
  153. // !($allowedUsers[$task->_l_app]) - to jest bez sensu - wystarczy widocznosc sprawy?
  154. ) {
  155. $tasks[$id]->_visible = false;
  156. }
  157. $tasks[$id]->_l_app_class = $przypomnij->getTaskDateFltrType($task->_l_app_date);
  158. $tasks[$id]->_idZasobTable = $przypomnij->getZasobIdByType($task->_task_type);
  159. }
  160. $filtersByType = new stdClass();
  161. $filtersByType->title = "Filtr";
  162. $filtersByType->icon = "filter";
  163. $filtersByType->prefix = "type-";
  164. $filtersByType->items = array();
  165. $filtersByType->items[] = 'PROJEKT';
  166. $filtersByType->items[] = 'KORESP';
  167. $filtersByType->items[] = 'PROCES';
  168. $filtersByType->items[] = 'TASK';
  169. $filtersByType->items[] = 'ZASOB';
  170. $filtersByType->isActive = array();
  171. $filtersByType->isActive['PROJEKT'] = true;
  172. $filtersByType->isActive['KORESP'] = true;
  173. $filtersByType->isActive['PROCES'] = true;
  174. $filtersByType->isActive['TASK'] = true;
  175. $filtersByType->isActive['ZASOB'] = true;
  176. $filtersByType->labels = array();
  177. $filtersByType->labels['PROJEKT'] = 'projekty';
  178. $filtersByType->labels['KORESP'] = 'koresp.';
  179. $filtersByType->labels['PROCES'] = 'procesy';
  180. $filtersByType->labels['TASK'] = 'zadania';
  181. $filtersByType->labels['ZASOB'] = 'zasoby';
  182. $filtersByType->itemTitles = array();
  183. $filtersByType->itemTitles['KORESP'] = 'Korespondencja';
  184. $dateFltrTypes = $przypomnij->getDateFltrTypes();
  185. $filtersByDate = new stdClass();
  186. $filtersByDate->title = "Data";
  187. $filtersByDate->icon = "calendar";
  188. $filtersByDate->prefix = "date-";
  189. $filtersByDate->items = array();
  190. $filtersByDate->items[] = 'PO_TERMINIE';
  191. $filtersByDate->items[] = 'DZISIAJ';
  192. $filtersByDate->items[] = 'W_CIAGU_7_DNI';
  193. $filtersByDate->items[] = 'PO_7_DNIACH';
  194. $filtersByDate->items[] = 'BRAK';
  195. $filtersByDate->isActive = array();
  196. $filtersByDate->isActive['PO_TERMINIE'] = true;
  197. $filtersByDate->isActive['DZISIAJ'] = true;
  198. $filtersByDate->isActive['W_CIAGU_7_DNI'] = true;
  199. $filtersByDate->isActive['PO_7_DNIACH'] = false;
  200. $filtersByDate->isActive['BRAK'] = false;
  201. $filtersByDate->labels = array();
  202. $filtersByDate->labels['PO_TERMINIE'] = 'po terminie';
  203. $filtersByDate->labels['DZISIAJ'] = 'dzisiaj';
  204. $filtersByDate->labels['W_CIAGU_7_DNI'] = 'w ciagu 7 dni';
  205. $filtersByDate->labels['PO_7_DNIACH'] = 'po 7 dniach';
  206. $filtersByDate->labels['BRAK'] = 'brak';
  207. $filtersByDate->itemTitles = array();
  208. $filtersByDate->itemTitles['KORESP'] = 'Korespondencja';
  209. $filters = array();
  210. $filters['type'] = $filtersByType;
  211. $filters['date'] = $filtersByDate;
  212. ?>
  213. <style type="text/css">
  214. .frm-przypomnij { width:96%; margin:0 auto 10px auto; table-layout:fixed; }
  215. .tbl-przypomnij { width:96%; margin:0 auto 10px auto; table-layout:fixed; }
  216. .tbl-przypomnij td,
  217. .tbl-przypomnij th { overflow:hidden; }
  218. .tbl-przypomnij .l_app_date { white-space:nowrap; }
  219. .tbl-przypomnij .date-PO_TERMINIE .l_app_date { color:#FD4242; }
  220. .tbl-przypomnij .date-DZISIAJ .l_app_date { color:#34B934; }
  221. .tbl-przypomnij .date-W_CIAGU_7_DNI .l_app_date { color:#C58B1F; }
  222. .tbl-przypomnij .date-PO_7_DNIACH .l_app_date { color:#87847D; }
  223. .use-filtr_only_stare tr.l-app-stare{display:none;}
  224. .fltr-hide_PROJEKT tr.type-PROJEKT {display:none;}
  225. .fltr-hide_KORESP tr.type-KORESP {display:none;}
  226. .fltr-hide_PROCES tr.type-PROCES {display:none;}
  227. .fltr-hide_TASK tr.type-TASK {display:none;}
  228. .fltr-hide_ZASOB tr.type-ZASOB {display:none;}
  229. .fltr-hide_PO_TERMINIE tr.date-PO_TERMINIE {display:none;}
  230. .fltr-hide_DZISIAJ tr.date-DZISIAJ {display:none;}
  231. .fltr-hide_W_CIAGU_7_DNI tr.date-W_CIAGU_7_DNI {display:none;}
  232. .fltr-hide_PO_7_DNIACH tr.date-PO_7_DNIACH {display:none;}
  233. .fltr-hide_BRAK tr.date-BRAK {display:none;}
  234. .nobr {white-space:nowrap;}
  235. .btn-default { background-color:#fff; }
  236. .btn-default:hover { background-color:#fafafa; }
  237. .bejm_inactive_btn-default { background-color:#e8e8e8; color:#888; }
  238. .bejm_inactive_btn-default:hover { background-color:#e4ede4; color:#666;}
  239. .bejm_active { background-color:#e5ffe6/*#d8ffda-mocniej zielony*/; color:#222; /* border-top: 1px solid #00e62b; border-bottom: 1px solid #00e62b; */ }
  240. .bejm_active:hover { background-color:#dcf4dd; color:#666; /* border-top: 1px solid #00e62b; border-bottom: 1px solid #00e62b; */ }
  241. </style>
  242. <div id="przypomnij-widget"></div>
  243. <script>
  244. ;(function($, window, document, undefined) {
  245. var pluginName = 'Przypomnij',
  246. defaults = {
  247. filters: {},
  248. tasks: [],
  249. debug: false
  250. };
  251. function Plugin(element, options) {
  252. this.element = element;
  253. // jQuery has an extend method that merges the
  254. // contents of two or more objects, storing the
  255. // result in the first object. The first object
  256. // is generally empty because we don't want to alter
  257. // the default options for future instances of the plugin
  258. this.options = $.extend({}, defaults, options);
  259. this._defaults = defaults;
  260. this._name = pluginName;
  261. this._tasks = this.options.tasks || [];
  262. this._filters = {};
  263. this._filterNodes = {};
  264. this._sortedTasks = {};
  265. this._tableNode = undefined;
  266. this._tbodyNode = undefined;
  267. this._inlineEditNode = undefined;
  268. this._filtersPanelNode = undefined;
  269. this._statsPanelNode = undefined;
  270. this._needRender = {
  271. TableBody: true,
  272. // FiltersPanel: false,
  273. StatsPanel: false
  274. };
  275. this.init();
  276. }
  277. Plugin.prototype.init = function() {
  278. this.log('init', '<?php echo __LINE__; ?>', [this]);
  279. this.initTasks();
  280. this.initFilters();
  281. this.initialRender();
  282. this.initEvents();
  283. this._tableNode.addClass('fltr-hide_PO_7_DNIACH fltr-hide_BRAK');// TODO: by setState / setFilters
  284. this.render();// render from State
  285. };
  286. Plugin.prototype.initTasks = function() {
  287. var self = this;
  288. this._sortedTasks = {// by task._task_type
  289. projekt: {},
  290. koresp: {},
  291. proces: {},
  292. task: {},
  293. };
  294. $.each(this._tasks, function(index, value) {
  295. var task = value;
  296. if (!self._sortedTasks.hasOwnProperty(task._task_type)) {
  297. self.log('unsupproted task type "'+task._task_type+'"', '<?php echo __LINE__; ?>', task);
  298. } else {
  299. self._sortedTasks[task._task_type][task.ID] = index;
  300. }
  301. });
  302. this.log('initTasks end', '<?php echo __LINE__; ?>', [this._sortedTasks]);
  303. };
  304. Plugin.prototype.initFilters = function() {
  305. var self = this;
  306. this._filters = {
  307. type: {},
  308. date: {}
  309. };
  310. $.each(this.options.filters, function(fltrType, fltr) {
  311. $.each(fltr.items, function(idx, itemName) {
  312. self._filters[fltrType][itemName] = false;
  313. });
  314. $.each(fltr.isActive, function(itemName, isActive) {
  315. self._filters[fltrType][itemName] = isActive;
  316. });
  317. });
  318. this.log('initFilters end', '<?php echo __LINE__; ?>', [this._filters, this.options.filters]);
  319. };
  320. Plugin.prototype.render = function() {
  321. var self = this;
  322. this.log('render', '<?php echo __LINE__; ?>', {_needRender: this._needRender});
  323. $.each(this._needRender, function(index, value) {
  324. if (value) {
  325. var renderMethodName = 'render' + index;
  326. if ('function' == typeof self[renderMethodName]) {
  327. self[renderMethodName](value);
  328. } else {
  329. self.log('render method "' + renderMethodName + '" not defined!', '<?php echo __LINE__; ?>');
  330. }
  331. self._needRender[index] = false;
  332. }
  333. });
  334. };
  335. Plugin.prototype.createTableHead = function() {
  336. var theadNode = $('<thead></thead>'),
  337. theadTrNode = $('<tr></tr>').appendTo(theadNode);
  338. $('<th style="width:120px">Termin wykonania</th>').appendTo(theadTrNode);
  339. $('<th style="width:20%">Opis działań do wykonania</th>').appendTo(theadTrNode);
  340. $('<th style="width:190px">Typ rekordu / ID</th>').appendTo(theadTrNode);
  341. $('<th>Firma powiąz. / adres / opis-temat</th>').appendTo(theadTrNode);
  342. $('<th style="width:100px">Lokalizacja</th>').appendTo(theadTrNode);
  343. return theadNode;
  344. };
  345. Plugin.prototype.renderTableBody = function(value) {
  346. var self = this,
  347. tbodyNodes = [];
  348. $.each(this._tasks, function(index, task) {
  349. var rowNode = $('<tr></tr>');
  350. rowNode.attr('id', 'row-' + task._task_type + '-' + task.ID);
  351. rowNode.addClass('type-' + task._task_type.toUpperCase());
  352. rowNode.addClass(task._l_app_class);
  353. if (!self.isTaskVisible(task)) {
  354. $('<td colspan="5" style="display:none">pomin task '+task.ID+'/'+task._task_type+'/'+task._title+'</td>').appendTo(rowNode);
  355. } else {
  356. var colLappNode = $('<td></td>'),
  357. colTaskNode = $('<td></td>'),
  358. colTypeNode = $('<td></td>'),
  359. colDescNode = $('<td></td>'),
  360. colLocationNode = $('<td></td>')
  361. ;
  362. {// colLappNode
  363. colLappNode.addClass('l_app_date-edit_inline');
  364. colLappNode.data('type', task._task_type);
  365. colLappNode.data('rowid', task.ID);
  366. $('<strong class="l_app_date">' + task._l_app_date + '</strong>').appendTo(colLappNode);
  367. var lappUser = '<em class="label label-important">Nieprzypisany!</em>';
  368. if (task._l_app) lappUser = '<em>' + task._l_app + '</em>';
  369. $('<div class="l_app_user">' + lappUser + '</div>').appendTo(colLappNode);
  370. }
  371. {// colTaskNode
  372. colTaskNode.addClass('l_app_info l_app_date-edit_inline');
  373. colTaskNode.data('type', task._task_type);
  374. colTaskNode.data('rowid', task.ID);
  375. colTaskNode.text(task.L_APPOITMENT_INFO);
  376. }
  377. {// colTypeNode
  378. var typeLinksNode = $('<h5></h5>').appendTo(colTypeNode);
  379. $('<span class="label label-A_STATUS-' + task.A_STATUS + '">' + task.A_STATUS + '</span>').appendTo(colTypeNode);
  380. if (task._type) $('<em>' + task._type + '</em>').appendTo(colTypeNode);
  381. var editLink = $('<a target="_blank" title="Edytuj rekord"></a>').appendTo(typeLinksNode);
  382. editLink.attr('href', 'index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' + task._idZasobTable + '#EDIT/' + task.ID);
  383. editLink.html('<i class="glyphicon glyphicon-pencil"></i>' + ' ' + task._task_type.toUpperCase() + ' ' + task.ID);
  384. typeLinksNode.append(document.createTextNode(' '));
  385. var filesLink = $('<a target="_blank" title="Pliki" style="margin-left:6px"></a>').appendTo(typeLinksNode);
  386. filesLink.attr('href', 'index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' + task._idZasobTable + '#FILES/' + task.ID);
  387. filesLink.html('<i class="glyphicon glyphicon-folder-open"></i>');
  388. var messagesLink = $('<a target="_blank" title="Wiadomości" style="margin-left:6px"></a>').appendTo(typeLinksNode);
  389. messagesLink.attr('href', 'index.php?_route=TableMsgs&_task=tableRow&idTable=' + task._idZasobTable + '&idRow=' + task.ID);
  390. messagesLink.html('<i class="glyphicon glyphicon-envelope"></i>');
  391. }
  392. {// colDescNode
  393. if ('projekt' == task._task_type && task.M_DISTRIBUTOR.length > 0) {
  394. colDescNode.html('<strong>' + task.M_DISTRIBUTOR + '</strong><br>' + task._title);
  395. } else {
  396. colDescNode.html(task._title);
  397. }
  398. }
  399. {// colLocationNode
  400. if ('koresp' == task._task_type) {
  401. colLocationNode.html('<em>' + task.K_LOKALIZACJA_OPIS + '</em>');
  402. }
  403. }
  404. colLappNode.appendTo(rowNode);
  405. colTaskNode.appendTo(rowNode);
  406. colTypeNode.appendTo(rowNode);
  407. colDescNode.appendTo(rowNode);
  408. colLocationNode.appendTo(rowNode);
  409. }
  410. tbodyNodes.push(rowNode);
  411. });
  412. this._tbodyNode.html(tbodyNodes);
  413. };
  414. Plugin.prototype.initEvents = function() {
  415. var self = this,
  416. _inlineEditBox = this._inlineEditNode,
  417. frmInlineEdit = _inlineEditBox.find('form');
  418. frmInlineEdit.on('submit', function() {
  419. var frmData = _inlineEditBox.find('form').serialize();
  420. var task_rowid = frmInlineEdit.find('input[name=rowid]').val();
  421. var task_type = frmInlineEdit.find('input[name=type]').val();
  422. _inlineEditBox.find('.btn-save').hide();
  423. _inlineEditBox.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  424. jQuery.ajax({
  425. url: 'index.php?_route=Przypomnij&_task=ajaxSaveInlineEdit',
  426. type: 'POST',
  427. dataType: 'text',
  428. data: frmData,
  429. async: true,
  430. success: function(data) {
  431. self.log('_inlineEditBox submit ajax data', '<?php echo __LINE__; ?>', data);
  432. _inlineEditBox.find('.inlineEditBox-cnt').html(data);
  433. _inlineEditBox.find('.btn-save').hide();
  434. var upNode = _inlineEditBox.find('.inlineEditBox-cnt').find('.EditAppDateInlineSave');
  435. if (upNode) {
  436. var newTask = {};
  437. if (upNode.find('.l_app_user')) {
  438. newTask.L_APPOITMENT_USER = upNode.find('.l_app_user').text();
  439. newTask._l_app = newTask.L_APPOITMENT_USER;
  440. }
  441. if (upNode.find('.l_app_date')) {
  442. newTask.L_APPOITMENT_DATE = upNode.find('.l_app_date').text();
  443. newTask._l_app_date = newTask.L_APPOITMENT_DATE;
  444. }
  445. if (upNode.find('.l_app_info')) {
  446. newTask.L_APPOITMENT_INFO = upNode.find('.l_app_info').text();
  447. }
  448. if (upNode.find('.date_fltr_type')) {
  449. newTask._l_app_class = upNode.find('.date_fltr_type').text();
  450. }
  451. self.updateTask(task_type, task_rowid, newTask);
  452. }
  453. },
  454. error: function(jhr, textStatus, errorThrown) {
  455. //console.log('_inlineEditBox submit ajax error');
  456. }
  457. });
  458. return false;
  459. });
  460. this._tbodyNode.on('dblclick', '.l_app_date-edit_inline', function(e){
  461. var data = $(this).data();
  462. // rowid: 2266, type: "projekt"
  463. if (!data.type || !data.rowid) {
  464. return false;
  465. }
  466. _inlineEditBox.modal();
  467. _inlineEditBox.show();
  468. _inlineEditBox.find('input[name=rowid]').val(data.rowid);
  469. _inlineEditBox.find('input[name=type]').val(data.type);
  470. _inlineEditBox.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  471. $.ajax({
  472. url: 'index.php?_route=Przypomnij&_task=ajaxInlineEdit',
  473. type: 'GET',
  474. dataType: 'text',
  475. data: data,
  476. async: true,
  477. success: function(data) {
  478. _inlineEditBox.find('.inlineEditBox-cnt').html(data);
  479. _inlineEditBox.find('.btn-save').show();
  480. initDateTimePicker(_inlineEditBox);
  481. _inlineEditBox.find('textarea').autosize();
  482. var fld = _inlineEditBox.find('input[id^="f"]');
  483. if (fld && !fld.hasClass('se_type-date')) {
  484. fld.focus();
  485. fld.keydown(function(event) {
  486. if (event.which == 13) {
  487. event.preventDefault();
  488. _inlineEditBox.find('form').submit();
  489. }
  490. });
  491. }
  492. },
  493. error: function(err) {
  494. console.log('err', err);
  495. }
  496. });
  497. });
  498. };
  499. Plugin.prototype.initialRender = function() {
  500. this.log('initialRender', '<?php echo __LINE__; ?>');
  501. this._filtersPanelNode = this.createFiltersPanelNode();
  502. $(this.element).append(this._filtersPanelNode);
  503. this._statsPanelNode = this.createStatsPanelNode();
  504. $(this.element).append(this._statsPanelNode);
  505. this._tableNode = $('<table></table>');
  506. this._tableNode.addClass('tbl-przypomnij');
  507. this._tableNode.addClass('table table-bordered table-hover');
  508. this.createTableHead().appendTo(this._tableNode);
  509. this._tbodyNode = $('<tbody></tbody>');
  510. this._tbodyNode.appendTo(this._tableNode);
  511. $(this.element).append(this._tableNode);
  512. this._inlineEditNode = this.createInlineEditBox();
  513. $(this.element).append(this._inlineEditNode);
  514. };
  515. Plugin.prototype.createFiltersPanelNode = function() {
  516. var self = this,
  517. filtersPanelNode = $('<div class="container" style="margin-top:8px;"></div>'),
  518. groupNode,
  519. btnNode,
  520. typeFiltersNode = $('<div class="btn-group"></div>').appendTo(filtersPanelNode),// TODO: RMME
  521. dateFiltersNode = $('<div class="btn-group"></div>').appendTo(filtersPanelNode)// TODO: RMME
  522. ;
  523. $.each(this._filters, function(fltrType, fltrItems) {
  524. self._filterNodes[fltrType] = {};
  525. groupNode = $('<div class="btn-group"></div>').appendTo(filtersPanelNode);
  526. var icon = self.options.filters[fltrType].icon;
  527. btnNode = $('<button class="btn btn-default" title="Filtr"><i class="glyphicon glyphicon-' + icon + '"></i></button>');
  528. btnNode.appendTo(groupNode);
  529. $.each(fltrItems, function(itemName, isActive) {
  530. btnNode = $('<button class="btn btn-default bejm_inactive_btn-default"></button>');
  531. btnNode.data('type', fltrType);
  532. btnNode.data('name', itemName);
  533. if (self.options.filters[fltrType]['itemTitles'][itemName]) {
  534. btnNode.attr('title', self.options.filters[fltrType]['itemTitles'][itemName]);
  535. }
  536. if (true === self._filters[fltrType][itemName]) {
  537. btnNode.addClass('bejm_active');
  538. }
  539. btnNode.text(self.options.filters[fltrType]['labels'][itemName]);
  540. //btnNode.html(self.options.filters[fltrType]['labels'][itemName] + ' <span class="badge" style="background-color: #aaa;">3</span>');// TODO: TEST badge
  541. btnNode.appendTo(groupNode);
  542. btnNode.on('click', function(e) {
  543. self.onClickFilter(e);
  544. });
  545. self._filterNodes[fltrType][itemName] = btnNode;
  546. });
  547. btnNode = $('<button class="btn btn-default disabled" title="Kasuj filtr do ustawień domyślnych"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(groupNode);
  548. btnNode.on('click', function(e) {
  549. self.onClickRestoreFilters(e, fltrType);
  550. });
  551. self._filterNodes[fltrType]['RESTORE_DEFAULT'] = btnNode;
  552. filtersPanelNode.append(document.createTextNode(' '));
  553. });
  554. return filtersPanelNode;
  555. };
  556. Plugin.prototype.createStatsPanelNode = function() {
  557. var statsPanelNode = $('<div class="container" style="margin-top:8px;margin-bottom:8px"></div>'),
  558. self = this,
  559. stats = {}
  560. ;
  561. stats['projekt'] = 0;
  562. stats['koresp'] = 0;
  563. stats['proces'] = 0;
  564. stats['task'] = 0;
  565. this.log('createStatsPanelNode', '<?php echo __LINE__; ?>', [this._filters]);
  566. $.each(this._tasks, function(idx, task) {
  567. if (!stats.hasOwnProperty(task._task_type)) {
  568. self.log('BUG stats has no property "'+task._task_type+'"', '<?php echo __LINE__; ?>', task);
  569. return;
  570. }
  571. if (!self.isTaskVisible(task)) {
  572. return;
  573. }
  574. var typeName = task._task_type.toUpperCase();
  575. if (self._filters['type'].hasOwnProperty(typeName)
  576. && true === self._filters['type'][typeName]) {
  577. } else {
  578. return;
  579. }
  580. var hasActiveFilter = false;
  581. $.each(self._filters['date'], function(itemName, isActive) {
  582. if (isActive) {
  583. if (task._l_app_class == 'date-' + itemName) {
  584. hasActiveFilter = true;
  585. }
  586. }
  587. });
  588. if (hasActiveFilter) {
  589. stats[task._task_type] += 1;
  590. }
  591. });
  592. $('<span>Ilość pism: ' + stats['projekt'] + ', </span>').appendTo(statsPanelNode);
  593. $('<span>ilość spraw: ' + stats['koresp'] + ', </span>').appendTo(statsPanelNode);
  594. $('<span>ilość procesów: ' + stats['proces'] + ', </span>').appendTo(statsPanelNode);
  595. $('<span>ilość zadań: ' + stats['task'] + '.</span>').appendTo(statsPanelNode);
  596. if (!stats['projekt'] && !stats['koresp'] && !stats['proces'] && !stats['task']) {
  597. $('<div class="alert alert-warning">Brak danych pasujących do wybranego filtra</div>').appendTo(statsPanelNode);
  598. }
  599. return statsPanelNode;
  600. };
  601. Plugin.prototype.onClickRestoreFilters = function(e, fltrType) {
  602. var self = this,
  603. n = $(e.target)
  604. ;
  605. this.log('onClickRestoreFilters', '<?php echo __LINE__; ?>', {fltrType: fltrType});
  606. $.each(this._filters[fltrType], function(itemName, isActive) {
  607. self._filters[fltrType][itemName] = self.options.filters[fltrType]['isActive'][itemName];
  608. });
  609. n.blur();
  610. this._afterUpdateFilters();
  611. };
  612. Plugin.prototype.onClickFilter = function(e) {
  613. var n = $(e.target),
  614. type = n.data('type'),
  615. name = n.data('name')
  616. ;
  617. this.log('onClickFilter', '<?php echo __LINE__; ?>', [n.data('type'), n.data('name'), n, e]);
  618. if (!type || !name || undefined === this._filters[type][name]) return;
  619. this._filters[type][name] = !this._filters[type][name];
  620. n.blur();
  621. this._afterUpdateFilters();
  622. };
  623. Plugin.prototype._afterUpdateFilters = function() {
  624. var self = this;
  625. this.log('_afterUpdateFilters', '<?php echo __LINE__; ?>');
  626. $.each(this._filters, function(fltrType, fltrItems) {
  627. var isDiffToDefault = false;
  628. $.each(fltrItems, function(itemName, isActive) {
  629. if (self.options.filters[fltrType]['isActive'][itemName] !== isActive) {
  630. isDiffToDefault = true;
  631. }
  632. var n = self._filterNodes[fltrType][itemName];
  633. if (isActive) {
  634. n.addClass('bejm_active');
  635. self._tableNode.removeClass('fltr-hide_' + itemName);
  636. } else {
  637. n.removeClass('bejm_active');
  638. self._tableNode.addClass('fltr-hide_' + itemName);
  639. }
  640. });
  641. var btnRestoreDefault = self._filterNodes[fltrType]['RESTORE_DEFAULT'];
  642. if (isDiffToDefault) {
  643. btnRestoreDefault.removeClass('disabled');
  644. } else {
  645. btnRestoreDefault.addClass('disabled');
  646. }
  647. });
  648. this.renderStatsPanel();
  649. };
  650. Plugin.prototype.updateTask = function(task_type, task_rowid, newTask) {
  651. this.log('updateTask', '<?php echo __LINE__; ?>', {task_type: task_type, ID: task_rowid, newTask: newTask});
  652. var taskIdx,
  653. task,
  654. taskChanged = false
  655. ;
  656. try {
  657. taskIdx = this._sortedTasks[task_type][task_rowid];
  658. task = this._tasks[taskIdx];
  659. this.log('updateTask task', '<?php echo __LINE__; ?>', {task: task});
  660. if (task) {
  661. if (newTask.hasOwnProperty('L_APPOITMENT_INFO') && newTask.L_APPOITMENT_INFO != task.L_APPOITMENT_INFO) {
  662. task.L_APPOITMENT_INFO = newTask.L_APPOITMENT_INFO;
  663. taskChanged = true;
  664. }
  665. if (newTask.hasOwnProperty('L_APPOITMENT_DATE') && newTask.L_APPOITMENT_DATE != task.L_APPOITMENT_DATE) {
  666. task.L_APPOITMENT_DATE = newTask.L_APPOITMENT_DATE;
  667. taskChanged = true;
  668. }
  669. if (newTask.hasOwnProperty('_l_app_date') && newTask._l_app_date != task._l_app_date) {
  670. task._l_app_date = newTask._l_app_date;
  671. taskChanged = true;
  672. }
  673. if (newTask.hasOwnProperty('L_APPOITMENT_USER') && newTask.L_APPOITMENT_USER != task.L_APPOITMENT_USER) {
  674. task.L_APPOITMENT_USER = newTask.L_APPOITMENT_USER;
  675. taskChanged = true;
  676. }
  677. if (newTask.hasOwnProperty('_l_app') && newTask._l_app != task._l_app) {
  678. task._l_app = newTask._l_app;
  679. taskChanged = true;
  680. }
  681. if (newTask.hasOwnProperty('_l_app_class') && newTask._l_app_class != task._l_app_class) {
  682. task._l_app_class = newTask._l_app_class;
  683. taskChanged = true;
  684. }
  685. this.log('updateTask task taskChanged', '<?php echo __LINE__; ?>', {task: task, taskChanged: taskChanged, taskStored: this._tasks[taskIdx]});
  686. }
  687. } catch(e) {
  688. this.log('error', '<?php echo __LINE__; ?>', e);
  689. }
  690. if (taskChanged) {
  691. this._needRender['TableBody'] = taskIdx;
  692. this._needRender['StatsPanel'] = true;
  693. this.render();
  694. }
  695. };
  696. Plugin.prototype.renderStatsPanel = function(value) {
  697. var statsPanelNode = this.createStatsPanelNode();
  698. this._statsPanelNode.replaceWith(statsPanelNode);
  699. this._statsPanelNode = statsPanelNode;
  700. };
  701. Plugin.prototype.createInlineEditBox = function() {
  702. var inlineEditBoxNode = $('<div class="inlineEditBox modal fade" role="dialog" aria-labelledby="przypomnijModalLabel" aria-hidden="true"></div>'),
  703. modalDialog = $('<div class="modal-dialog"></div>').appendTo(inlineEditBoxNode),
  704. modalContent = $('<div class="modal-content"></div>').appendTo(modalDialog),
  705. form = $('<form style="margin:0;padding:0;"></form>').appendTo(modalContent),
  706. modalHeader = $('<div class="modal-header"></div>').appendTo(form),
  707. headCloseBtn = $('<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(modalHeader),
  708. headLabel = $('<h3 id="przypomnijModalLabel">Edytuj</h3>').appendTo(modalHeader),
  709. modalBody = $('<div class="modal-body"></div>').appendTo(form),
  710. fldRowId = $('<input type="hidden" name="rowid" value="">').appendTo(modalBody),
  711. fldType = $('<input type="hidden" name="type" value="">').appendTo(modalBody),
  712. inlineContent = $('<div class="inlineEditBox-cnt"></div>').appendTo(modalBody),
  713. modalFooter = $('<div class="modal-footer"></div>').appendTo(form),
  714. footerCloseBtn = $('<button class="btn" data-dismiss="modal" aria-hidden="true">Zamknij</button>').appendTo(modalFooter),
  715. footerSubmitBtn = $('<input type="submit" value="Zapisz" class="btn btn-primary btn-save">').appendTo(modalFooter)
  716. ;
  717. return inlineEditBoxNode;
  718. };
  719. Plugin.prototype.isTaskVisible = function(task) {
  720. if (task._show !== true) {
  721. return false;
  722. }
  723. if (task._visible !== true) {
  724. return false;
  725. }
  726. return true;
  727. };
  728. Plugin.prototype.log = function(msg, code, variables) {
  729. var code = code || 0,
  730. variables = variables || undefined;
  731. if (this.options.debug && console && 'function' == typeof console.log) {
  732. console.log(this._name + '#' + code + ':' + msg, variables);
  733. }
  734. };
  735. $.fn[pluginName] = function(options) {
  736. return this.each(function() {
  737. if (!$.data(this, 'plugin_' + pluginName)) {
  738. $.data(this, 'plugin_' + pluginName,
  739. new Plugin(this, options));
  740. }
  741. });
  742. }
  743. })(jQuery, window, document);
  744. </script>
  745. <script>
  746. jQuery(document).ready(function() {
  747. jQuery('#przypomnij-widget').Przypomnij({
  748. debug: false,
  749. filters: <?php echo json_encode($filters); ?>,
  750. tasks: <?php echo json_encode($tasks); ?>
  751. });
  752. });
  753. </script>
  754. <?php
  755. }
  756. public function ajaxInlineEditAction() {
  757. // $_GET [rowid] => 2286, [type] => proces
  758. $przypomnij = $this->getModel();
  759. $przypomnij->sendAjaxEditAppDateInline();
  760. }
  761. public function ajaxSaveInlineEditAction() {
  762. // $_GET [rowid] => 2286, [type] => proces, [fldId] => date
  763. $przypomnij = $this->getModel();
  764. $przypomnij->sendAjaxEditAppDateInlineSave();
  765. }
  766. }