Przypomnij.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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. </style>
  236. <div id="przypomnij-widget"></div>
  237. <script>
  238. ;(function($, window, document, undefined) {
  239. var pluginName = 'Przypomnij',
  240. defaults = {
  241. filters: {},
  242. tasks: [],
  243. debug: false
  244. };
  245. function Plugin(element, options) {
  246. this.element = element;
  247. // jQuery has an extend method that merges the
  248. // contents of two or more objects, storing the
  249. // result in the first object. The first object
  250. // is generally empty because we don't want to alter
  251. // the default options for future instances of the plugin
  252. this.options = $.extend({}, defaults, options);
  253. this._defaults = defaults;
  254. this._name = pluginName;
  255. this._tasks = this.options.tasks || [];
  256. this._filters = {};
  257. this._filterNodes = {};
  258. this._sortedTasks = {};
  259. this._tableNode = undefined;
  260. this._tbodyNode = undefined;
  261. this._inlineEditNode = undefined;
  262. this._filtersPanelNode = undefined;
  263. this._statsPanelNode = undefined;
  264. this._needRender = {
  265. TableBody: true,
  266. // FiltersPanel: false,
  267. StatsPanel: false
  268. };
  269. this.init();
  270. }
  271. Plugin.prototype.init = function() {
  272. this.log('init', '<?php echo __LINE__; ?>', [this]);
  273. this.initTasks();
  274. this.initFilters();
  275. this.initialRender();
  276. this.initEvents();
  277. this._tableNode.addClass('fltr-hide_PO_7_DNIACH fltr-hide_BRAK');// TODO: by setState / setFilters
  278. this.render();// render from State
  279. };
  280. Plugin.prototype.initTasks = function() {
  281. var self = this;
  282. this._sortedTasks = {// by task._task_type
  283. projekt: {},
  284. koresp: {},
  285. proces: {},
  286. task: {},
  287. };
  288. $.each(this._tasks, function(index, value) {
  289. var task = value;
  290. if (!self._sortedTasks.hasOwnProperty(task._task_type)) {
  291. self.log('unsupproted task type "'+task._task_type+'"', '<?php echo __LINE__; ?>', task);
  292. } else {
  293. self._sortedTasks[task._task_type][task.ID] = index;
  294. }
  295. });
  296. this.log('initTasks end', '<?php echo __LINE__; ?>', [this._sortedTasks]);
  297. };
  298. Plugin.prototype.initFilters = function() {
  299. var self = this;
  300. this._filters = {
  301. type: {},
  302. date: {}
  303. };
  304. $.each(this.options.filters, function(fltrType, fltr) {
  305. $.each(fltr.items, function(idx, itemName) {
  306. self._filters[fltrType][itemName] = false;
  307. });
  308. $.each(fltr.isActive, function(itemName, isActive) {
  309. self._filters[fltrType][itemName] = isActive;
  310. });
  311. });
  312. this.log('initFilters end', '<?php echo __LINE__; ?>', [this._filters, this.options.filters]);
  313. };
  314. Plugin.prototype.render = function() {
  315. var self = this;
  316. this.log('render', '<?php echo __LINE__; ?>', {_needRender: this._needRender});
  317. $.each(this._needRender, function(index, value) {
  318. if (value) {
  319. var renderMethodName = 'render' + index;
  320. if ('function' == typeof self[renderMethodName]) {
  321. self[renderMethodName](value);
  322. } else {
  323. self.log('render method "' + renderMethodName + '" not defined!', '<?php echo __LINE__; ?>');
  324. }
  325. self._needRender[index] = false;
  326. }
  327. });
  328. };
  329. Plugin.prototype.createTableHead = function() {
  330. var theadNode = $('<thead></thead>'),
  331. theadTrNode = $('<tr></tr>').appendTo(theadNode);
  332. $('<th style="width:120px">Termin wykonania</th>').appendTo(theadTrNode);
  333. $('<th style="width:20%">Opis działań do wykonania</th>').appendTo(theadTrNode);
  334. $('<th style="width:190px">Typ rekordu / ID</th>').appendTo(theadTrNode);
  335. $('<th>Firma powiąz. / adres / opis-temat</th>').appendTo(theadTrNode);
  336. $('<th style="width:100px">Lokalizacja</th>').appendTo(theadTrNode);
  337. return theadNode;
  338. };
  339. Plugin.prototype.renderTableBody = function(value) {
  340. var self = this,
  341. tbodyNodes = [];
  342. $.each(this._tasks, function(index, task) {
  343. var rowNode = $('<tr></tr>');
  344. rowNode.attr('id', 'row-' + task._task_type + '-' + task.ID);
  345. rowNode.addClass('type-' + task._task_type.toUpperCase());
  346. rowNode.addClass(task._l_app_class);
  347. if (!self.isTaskVisible(task)) {
  348. $('<td colspan="5" style="display:none">pomin task '+task.ID+'/'+task._task_type+'/'+task._title+'</td>').appendTo(rowNode);
  349. } else {
  350. var colLappNode = $('<td></td>'),
  351. colTaskNode = $('<td></td>'),
  352. colTypeNode = $('<td></td>'),
  353. colDescNode = $('<td></td>'),
  354. colLocationNode = $('<td></td>')
  355. ;
  356. {// colLappNode
  357. colLappNode.addClass('l_app_date-edit_inline');
  358. colLappNode.data('type', task._task_type);
  359. colLappNode.data('rowid', task.ID);
  360. $('<strong class="l_app_date">' + task._l_app_date + '</strong>').appendTo(colLappNode);
  361. var lappUser = '<em class="label label-important">Nieprzypisany!</em>';
  362. if (task._l_app) lappUser = '<em>' + task._l_app + '</em>';
  363. $('<div class="l_app_user">' + lappUser + '</div>').appendTo(colLappNode);
  364. }
  365. {// colTaskNode
  366. colTaskNode.addClass('l_app_info l_app_date-edit_inline');
  367. colTaskNode.data('type', task._task_type);
  368. colTaskNode.data('rowid', task.ID);
  369. colTaskNode.text(task.L_APPOITMENT_INFO);
  370. }
  371. {// colTypeNode
  372. var typeLinksNode = $('<h5></h5>').appendTo(colTypeNode);
  373. $('<span class="label label-A_STATUS-' + task.A_STATUS + '">' + task.A_STATUS + '</span>').appendTo(colTypeNode);
  374. if (task._type) $('<em>' + task._type + '</em>').appendTo(colTypeNode);
  375. var editLink = $('<a target="_blank" title="Edytuj rekord"></a>').appendTo(typeLinksNode);
  376. editLink.attr('href', 'index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' + task._idZasobTable + '#EDIT/' + task.ID);
  377. editLink.html('<i class="glyphicon glyphicon-pencil"></i>' + ' ' + task._task_type.toUpperCase() + ' ' + task.ID);
  378. typeLinksNode.append(document.createTextNode(' '));
  379. var filesLink = $('<a target="_blank" title="Pliki" style="margin-left:6px"></a>').appendTo(typeLinksNode);
  380. filesLink.attr('href', 'index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' + task._idZasobTable + '#FILES/' + task.ID);
  381. filesLink.html('<i class="glyphicon glyphicon-folder-open"></i>');
  382. var messagesLink = $('<a target="_blank" title="Wiadomości" style="margin-left:6px"></a>').appendTo(typeLinksNode);
  383. messagesLink.attr('href', 'index.php?_route=TableMsgs&_task=tableRow&idTable=' + task._idZasobTable + '&idRow=' + task.ID);
  384. messagesLink.html('<i class="glyphicon glyphicon-envelope"></i>');
  385. }
  386. {// colDescNode
  387. if ('projekt' == task._task_type && task.M_DISTRIBUTOR.length > 0) {
  388. colDescNode.html('<strong>' + task.M_DISTRIBUTOR + '</strong><br>' + task._title);
  389. } else {
  390. colDescNode.html(task._title);
  391. }
  392. }
  393. {// colLocationNode
  394. if ('koresp' == task._task_type) {
  395. colLocationNode.html('<em>' + task.K_LOKALIZACJA_OPIS + '</em>');
  396. }
  397. }
  398. colLappNode.appendTo(rowNode);
  399. colTaskNode.appendTo(rowNode);
  400. colTypeNode.appendTo(rowNode);
  401. colDescNode.appendTo(rowNode);
  402. colLocationNode.appendTo(rowNode);
  403. }
  404. tbodyNodes.push(rowNode);
  405. });
  406. this._tbodyNode.html(tbodyNodes);
  407. };
  408. Plugin.prototype.initEvents = function() {
  409. var self = this,
  410. _inlineEditBox = this._inlineEditNode,
  411. frmInlineEdit = _inlineEditBox.find('form');
  412. frmInlineEdit.on('submit', function() {
  413. var frmData = _inlineEditBox.find('form').serialize();
  414. var task_rowid = frmInlineEdit.find('input[name=rowid]').val();
  415. var task_type = frmInlineEdit.find('input[name=type]').val();
  416. _inlineEditBox.find('.btn-save').hide();
  417. _inlineEditBox.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  418. jQuery.ajax({
  419. url: 'index.php?_route=Przypomnij&_task=ajaxSaveInlineEdit',
  420. type: 'POST',
  421. dataType: 'text',
  422. data: frmData,
  423. async: true,
  424. success: function(data) {
  425. self.log('_inlineEditBox submit ajax data', '<?php echo __LINE__; ?>', data);
  426. _inlineEditBox.find('.inlineEditBox-cnt').html(data);
  427. _inlineEditBox.find('.btn-save').hide();
  428. var upNode = _inlineEditBox.find('.inlineEditBox-cnt').find('.EditAppDateInlineSave');
  429. if (upNode) {
  430. var newTask = {};
  431. if (upNode.find('.l_app_user')) {
  432. newTask.L_APPOITMENT_USER = upNode.find('.l_app_user').text();
  433. newTask._l_app = newTask.L_APPOITMENT_USER;
  434. }
  435. if (upNode.find('.l_app_date')) {
  436. newTask.L_APPOITMENT_DATE = upNode.find('.l_app_date').text();
  437. newTask._l_app_date = newTask.L_APPOITMENT_DATE;
  438. }
  439. if (upNode.find('.l_app_info')) {
  440. newTask.L_APPOITMENT_INFO = upNode.find('.l_app_info').text();
  441. }
  442. if (upNode.find('.date_fltr_type')) {
  443. newTask._l_app_class = upNode.find('.date_fltr_type').text();
  444. }
  445. self.updateTask(task_type, task_rowid, newTask);
  446. }
  447. },
  448. error: function(jhr, textStatus, errorThrown) {
  449. //console.log('_inlineEditBox submit ajax error');
  450. }
  451. });
  452. return false;
  453. });
  454. this._tbodyNode.on('dblclick', '.l_app_date-edit_inline', function(e){
  455. var data = $(this).data();
  456. // rowid: 2266, type: "projekt"
  457. if (!data.type || !data.rowid) {
  458. return false;
  459. }
  460. _inlineEditBox.modal();
  461. _inlineEditBox.show();
  462. _inlineEditBox.find('input[name=rowid]').val(data.rowid);
  463. _inlineEditBox.find('input[name=type]').val(data.type);
  464. _inlineEditBox.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  465. $.ajax({
  466. url: 'index.php?_route=Przypomnij&_task=ajaxInlineEdit',
  467. type: 'GET',
  468. dataType: 'text',
  469. data: data,
  470. async: true,
  471. success: function(data) {
  472. _inlineEditBox.find('.inlineEditBox-cnt').html(data);
  473. _inlineEditBox.find('.btn-save').show();
  474. initDateTimePicker(_inlineEditBox);
  475. _inlineEditBox.find('textarea').autosize();
  476. var fld = _inlineEditBox.find('input[id^="f"]');
  477. if (fld && !fld.hasClass('se_type-date')) {
  478. fld.focus();
  479. fld.keydown(function(event) {
  480. if (event.which == 13) {
  481. event.preventDefault();
  482. _inlineEditBox.find('form').submit();
  483. }
  484. });
  485. }
  486. },
  487. error: function(err) {
  488. console.log('err', err);
  489. }
  490. });
  491. });
  492. };
  493. Plugin.prototype.initialRender = function() {
  494. this.log('initialRender', '<?php echo __LINE__; ?>');
  495. this._filtersPanelNode = this.createFiltersPanelNode();
  496. $(this.element).append(this._filtersPanelNode);
  497. this._statsPanelNode = this.createStatsPanelNode();
  498. $(this.element).append(this._statsPanelNode);
  499. this._tableNode = $('<table></table>');
  500. this._tableNode.addClass('tbl-przypomnij');
  501. this._tableNode.addClass('table table-bordered table-hover');
  502. this.createTableHead().appendTo(this._tableNode);
  503. this._tbodyNode = $('<tbody></tbody>');
  504. this._tbodyNode.appendTo(this._tableNode);
  505. $(this.element).append(this._tableNode);
  506. this._inlineEditNode = this.createInlineEditBox();
  507. $(this.element).append(this._inlineEditNode);
  508. };
  509. Plugin.prototype.createFiltersPanelNode = function() {
  510. var self = this,
  511. filtersPanelNode = $('<div class="container" style="margin-top:8px;"></div>'),
  512. groupNode,
  513. btnNode,
  514. typeFiltersNode = $('<div class="btn-group"></div>').appendTo(filtersPanelNode),// TODO: RMME
  515. dateFiltersNode = $('<div class="btn-group"></div>').appendTo(filtersPanelNode)// TODO: RMME
  516. ;
  517. $.each(this._filters, function(fltrType, fltrItems) {
  518. self._filterNodes[fltrType] = {};
  519. groupNode = $('<div class="btn-group"></div>').appendTo(filtersPanelNode);
  520. var icon = self.options.filters[fltrType].icon;
  521. btnNode = $('<button class="btn btn-default" title="Filtr"><i class="glyphicon glyphicon-' + icon + '"></i></button>');
  522. btnNode.appendTo(groupNode);
  523. $.each(fltrItems, function(itemName, isActive) {
  524. btnNode = $('<button class="btn btn-default"></button>');
  525. btnNode.data('type', fltrType);
  526. btnNode.data('name', itemName);
  527. if (self.options.filters[fltrType]['itemTitles'][itemName]) {
  528. btnNode.attr('title', self.options.filters[fltrType]['itemTitles'][itemName]);
  529. }
  530. if (true === self._filters[fltrType][itemName]) {
  531. btnNode.addClass('active');
  532. }
  533. btnNode.text(self.options.filters[fltrType]['labels'][itemName]);
  534. //btnNode.html(self.options.filters[fltrType]['labels'][itemName] + ' <span class="badge" style="background-color: #aaa;">3</span>');// TODO: TEST badge
  535. btnNode.appendTo(groupNode);
  536. btnNode.on('click', function(e) {
  537. self.onClickFilter(e);
  538. });
  539. self._filterNodes[fltrType][itemName] = btnNode;
  540. });
  541. btnNode = $('<button class="btn btn-default disabled" title="Kasuj filtr do ustawień domyślnych"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(groupNode);
  542. btnNode.on('click', function(e) {
  543. self.onClickRestoreFilters(e, fltrType);
  544. });
  545. self._filterNodes[fltrType]['RESTORE_DEFAULT'] = btnNode;
  546. filtersPanelNode.append(document.createTextNode(' '));
  547. });
  548. return filtersPanelNode;
  549. };
  550. Plugin.prototype.createStatsPanelNode = function() {
  551. var statsPanelNode = $('<div class="container" style="margin-top:8px;margin-bottom:8px"></div>'),
  552. self = this,
  553. stats = {}
  554. ;
  555. stats['projekt'] = 0;
  556. stats['koresp'] = 0;
  557. stats['proces'] = 0;
  558. stats['task'] = 0;
  559. this.log('createStatsPanelNode', '<?php echo __LINE__; ?>', [this._filters]);
  560. $.each(this._tasks, function(idx, task) {
  561. if (!stats.hasOwnProperty(task._task_type)) {
  562. self.log('BUG stats has no property "'+task._task_type+'"', '<?php echo __LINE__; ?>', task);
  563. return;
  564. }
  565. if (!self.isTaskVisible(task)) {
  566. return;
  567. }
  568. var typeName = task._task_type.toUpperCase();
  569. if (self._filters['type'].hasOwnProperty(typeName)
  570. && true === self._filters['type'][typeName]) {
  571. } else {
  572. return;
  573. }
  574. var hasActiveFilter = false;
  575. $.each(self._filters['date'], function(itemName, isActive) {
  576. if (isActive) {
  577. if (task._l_app_class == 'date-' + itemName) {
  578. hasActiveFilter = true;
  579. }
  580. }
  581. });
  582. if (hasActiveFilter) {
  583. stats[task._task_type] += 1;
  584. }
  585. });
  586. $('<span>Ilość pism: ' + stats['projekt'] + ', </span>').appendTo(statsPanelNode);
  587. $('<span>ilość spraw: ' + stats['koresp'] + ', </span>').appendTo(statsPanelNode);
  588. $('<span>ilość procesów: ' + stats['proces'] + ', </span>').appendTo(statsPanelNode);
  589. $('<span>ilość zadań: ' + stats['task'] + '.</span>').appendTo(statsPanelNode);
  590. if (!stats['projekt'] && !stats['koresp'] && !stats['proces'] && !stats['task']) {
  591. $('<div class="alert alert-warning">Brak danych pasujących do wybranego filtra</div>').appendTo(statsPanelNode);
  592. }
  593. return statsPanelNode;
  594. };
  595. Plugin.prototype.onClickRestoreFilters = function(e, fltrType) {
  596. var self = this,
  597. n = $(e.target)
  598. ;
  599. this.log('onClickRestoreFilters', '<?php echo __LINE__; ?>', {fltrType: fltrType});
  600. $.each(this._filters[fltrType], function(itemName, isActive) {
  601. self._filters[fltrType][itemName] = self.options.filters[fltrType]['isActive'][itemName];
  602. });
  603. n.blur();
  604. this._afterUpdateFilters();
  605. };
  606. Plugin.prototype.onClickFilter = function(e) {
  607. var n = $(e.target),
  608. type = n.data('type'),
  609. name = n.data('name')
  610. ;
  611. this.log('onClickFilter', '<?php echo __LINE__; ?>', [n.data('type'), n.data('name'), n, e]);
  612. if (!type || !name || undefined === this._filters[type][name]) return;
  613. this._filters[type][name] = !this._filters[type][name];
  614. n.blur();
  615. this._afterUpdateFilters();
  616. };
  617. Plugin.prototype._afterUpdateFilters = function() {
  618. var self = this;
  619. this.log('_afterUpdateFilters', '<?php echo __LINE__; ?>');
  620. $.each(this._filters, function(fltrType, fltrItems) {
  621. var isDiffToDefault = false;
  622. $.each(fltrItems, function(itemName, isActive) {
  623. if (self.options.filters[fltrType]['isActive'][itemName] !== isActive) {
  624. isDiffToDefault = true;
  625. }
  626. var n = self._filterNodes[fltrType][itemName];
  627. if (isActive) {
  628. n.addClass('active');
  629. self._tableNode.removeClass('fltr-hide_' + itemName);
  630. } else {
  631. n.removeClass('active');
  632. self._tableNode.addClass('fltr-hide_' + itemName);
  633. }
  634. });
  635. var btnRestoreDefault = self._filterNodes[fltrType]['RESTORE_DEFAULT'];
  636. if (isDiffToDefault) {
  637. btnRestoreDefault.removeClass('disabled');
  638. } else {
  639. btnRestoreDefault.addClass('disabled');
  640. }
  641. });
  642. this.renderStatsPanel();
  643. };
  644. Plugin.prototype.updateTask = function(task_type, task_rowid, newTask) {
  645. this.log('updateTask', '<?php echo __LINE__; ?>', {task_type: task_type, ID: task_rowid, newTask: newTask});
  646. var taskIdx,
  647. task,
  648. taskChanged = false
  649. ;
  650. try {
  651. taskIdx = this._sortedTasks[task_type][task_rowid];
  652. task = this._tasks[taskIdx];
  653. this.log('updateTask task', '<?php echo __LINE__; ?>', {task: task});
  654. if (task) {
  655. if (newTask.hasOwnProperty('L_APPOITMENT_INFO') && newTask.L_APPOITMENT_INFO != task.L_APPOITMENT_INFO) {
  656. task.L_APPOITMENT_INFO = newTask.L_APPOITMENT_INFO;
  657. taskChanged = true;
  658. }
  659. if (newTask.hasOwnProperty('L_APPOITMENT_DATE') && newTask.L_APPOITMENT_DATE != task.L_APPOITMENT_DATE) {
  660. task.L_APPOITMENT_DATE = newTask.L_APPOITMENT_DATE;
  661. taskChanged = true;
  662. }
  663. if (newTask.hasOwnProperty('_l_app_date') && newTask._l_app_date != task._l_app_date) {
  664. task._l_app_date = newTask._l_app_date;
  665. taskChanged = true;
  666. }
  667. if (newTask.hasOwnProperty('L_APPOITMENT_USER') && newTask.L_APPOITMENT_USER != task.L_APPOITMENT_USER) {
  668. task.L_APPOITMENT_USER = newTask.L_APPOITMENT_USER;
  669. taskChanged = true;
  670. }
  671. if (newTask.hasOwnProperty('_l_app') && newTask._l_app != task._l_app) {
  672. task._l_app = newTask._l_app;
  673. taskChanged = true;
  674. }
  675. if (newTask.hasOwnProperty('_l_app_class') && newTask._l_app_class != task._l_app_class) {
  676. task._l_app_class = newTask._l_app_class;
  677. taskChanged = true;
  678. }
  679. this.log('updateTask task taskChanged', '<?php echo __LINE__; ?>', {task: task, taskChanged: taskChanged, taskStored: this._tasks[taskIdx]});
  680. }
  681. } catch(e) {
  682. this.log('error', '<?php echo __LINE__; ?>', e);
  683. }
  684. if (taskChanged) {
  685. this._needRender['TableBody'] = taskIdx;
  686. this._needRender['StatsPanel'] = true;
  687. this.render();
  688. }
  689. };
  690. Plugin.prototype.renderStatsPanel = function(value) {
  691. var statsPanelNode = this.createStatsPanelNode();
  692. this._statsPanelNode.replaceWith(statsPanelNode);
  693. this._statsPanelNode = statsPanelNode;
  694. };
  695. Plugin.prototype.createInlineEditBox = function() {
  696. var inlineEditBoxNode = $('<div class="inlineEditBox modal fade" role="dialog" aria-labelledby="przypomnijModalLabel" aria-hidden="true"></div>'),
  697. modalDialog = $('<div class="modal-dialog"></div>').appendTo(inlineEditBoxNode),
  698. modalContent = $('<div class="modal-content"></div>').appendTo(modalDialog),
  699. form = $('<form style="margin:0;padding:0;"></form>').appendTo(modalContent),
  700. modalHeader = $('<div class="modal-header"></div>').appendTo(form),
  701. headCloseBtn = $('<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(modalHeader),
  702. headLabel = $('<h3 id="przypomnijModalLabel">Edytuj</h3>').appendTo(modalHeader),
  703. modalBody = $('<div class="modal-body"></div>').appendTo(form),
  704. fldRowId = $('<input type="hidden" name="rowid" value="">').appendTo(modalBody),
  705. fldType = $('<input type="hidden" name="type" value="">').appendTo(modalBody),
  706. inlineContent = $('<div class="inlineEditBox-cnt"></div>').appendTo(modalBody),
  707. modalFooter = $('<div class="modal-footer"></div>').appendTo(form),
  708. footerCloseBtn = $('<button class="btn" data-dismiss="modal" aria-hidden="true">Zamknij</button>').appendTo(modalFooter),
  709. footerSubmitBtn = $('<input type="submit" value="Zapisz" class="btn btn-primary btn-save">').appendTo(modalFooter)
  710. ;
  711. return inlineEditBoxNode;
  712. };
  713. Plugin.prototype.isTaskVisible = function(task) {
  714. if (task._show !== true) {
  715. return false;
  716. }
  717. if (task._visible !== true) {
  718. return false;
  719. }
  720. return true;
  721. };
  722. Plugin.prototype.log = function(msg, code, variables) {
  723. var code = code || 0,
  724. variables = variables || undefined;
  725. if (this.options.debug && console && 'function' == typeof console.log) {
  726. console.log(this._name + '#' + code + ':' + msg, variables);
  727. }
  728. };
  729. $.fn[pluginName] = function(options) {
  730. return this.each(function() {
  731. if (!$.data(this, 'plugin_' + pluginName)) {
  732. $.data(this, 'plugin_' + pluginName,
  733. new Plugin(this, options));
  734. }
  735. });
  736. }
  737. })(jQuery, window, document);
  738. </script>
  739. <script>
  740. jQuery(document).ready(function() {
  741. jQuery('#przypomnij-widget').Przypomnij({
  742. debug: false,
  743. filters: <?php echo json_encode($filters); ?>,
  744. tasks: <?php echo json_encode($tasks); ?>
  745. });
  746. });
  747. </script>
  748. <?php
  749. }
  750. public function ajaxInlineEditAction() {
  751. // $_GET [rowid] => 2286, [type] => proces
  752. $przypomnij = $this->getModel();
  753. $przypomnij->sendAjaxEditAppDateInline();
  754. }
  755. public function ajaxSaveInlineEditAction() {
  756. // $_GET [rowid] => 2286, [type] => proces, [fldId] => date
  757. $przypomnij = $this->getModel();
  758. $przypomnij->sendAjaxEditAppDateInlineSave();
  759. }
  760. }