Przypomnij.php 28 KB

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