Przypomnij.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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"></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> pliki');
  382. }
  383. {// colDescNode
  384. if ('projekt' == task._task_type && task.M_DISTRIBUTOR.length > 0) {
  385. colDescNode.html('<strong>' + task.M_DISTRIBUTOR + '</strong><br>' + task._title);
  386. } else {
  387. colDescNode.html(task._title);
  388. }
  389. }
  390. {// colLocationNode
  391. if ('koresp' == task._task_type) {
  392. colLocationNode.html('<em>' + task.K_LOKALIZACJA_OPIS + '</em>');
  393. }
  394. }
  395. colLappNode.appendTo(rowNode);
  396. colTaskNode.appendTo(rowNode);
  397. colTypeNode.appendTo(rowNode);
  398. colDescNode.appendTo(rowNode);
  399. colLocationNode.appendTo(rowNode);
  400. }
  401. tbodyNodes.push(rowNode);
  402. });
  403. this._tbodyNode.html(tbodyNodes);
  404. };
  405. Plugin.prototype.initEvents = function() {
  406. var self = this,
  407. _inlineEditBox = this._inlineEditNode,
  408. frmInlineEdit = _inlineEditBox.find('form');
  409. frmInlineEdit.on('submit', function() {
  410. var frmData = _inlineEditBox.find('form').serialize();
  411. var task_rowid = frmInlineEdit.find('input[name=rowid]').val();
  412. var task_type = frmInlineEdit.find('input[name=type]').val();
  413. _inlineEditBox.find('.btn-save').hide();
  414. _inlineEditBox.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  415. jQuery.ajax({
  416. url: 'index.php?_route=Przypomnij&_task=ajaxSaveInlineEdit',
  417. type: 'POST',
  418. dataType: 'text',
  419. data: frmData,
  420. async: true,
  421. success: function(data) {
  422. self.log('_inlineEditBox submit ajax data', '<?php echo __LINE__; ?>', data);
  423. _inlineEditBox.find('.inlineEditBox-cnt').html(data);
  424. _inlineEditBox.find('.btn-save').hide();
  425. var upNode = _inlineEditBox.find('.inlineEditBox-cnt').find('.EditAppDateInlineSave');
  426. if (upNode) {
  427. var newTask = {};
  428. if (upNode.find('.l_app_user')) {
  429. newTask.L_APPOITMENT_USER = upNode.find('.l_app_user').text();
  430. newTask._l_app = newTask.L_APPOITMENT_USER;
  431. }
  432. if (upNode.find('.l_app_date')) {
  433. newTask.L_APPOITMENT_DATE = upNode.find('.l_app_date').text();
  434. newTask._l_app_date = newTask.L_APPOITMENT_DATE;
  435. }
  436. if (upNode.find('.l_app_info')) {
  437. newTask.L_APPOITMENT_INFO = upNode.find('.l_app_info').text();
  438. }
  439. if (upNode.find('.date_fltr_type')) {
  440. newTask._l_app_class = upNode.find('.date_fltr_type').text();
  441. }
  442. self.updateTask(task_type, task_rowid, newTask);
  443. }
  444. },
  445. error: function(jhr, textStatus, errorThrown) {
  446. //console.log('_inlineEditBox submit ajax error');
  447. }
  448. });
  449. return false;
  450. });
  451. this._tbodyNode.on('dblclick', '.l_app_date-edit_inline', function(e){
  452. var data = $(this).data();
  453. // rowid: 2266, type: "projekt"
  454. if (!data.type || !data.rowid) {
  455. return false;
  456. }
  457. _inlineEditBox.modal();
  458. _inlineEditBox.show();
  459. _inlineEditBox.find('input[name=rowid]').val(data.rowid);
  460. _inlineEditBox.find('input[name=type]').val(data.type);
  461. _inlineEditBox.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  462. $.ajax({
  463. url: 'index.php?_route=Przypomnij&_task=ajaxInlineEdit',
  464. type: 'GET',
  465. dataType: 'text',
  466. data: data,
  467. async: true,
  468. success: function(data) {
  469. _inlineEditBox.find('.inlineEditBox-cnt').html(data);
  470. _inlineEditBox.find('.btn-save').show();
  471. initDateTimePicker(_inlineEditBox);
  472. _inlineEditBox.find('textarea').autosize();
  473. var fld = _inlineEditBox.find('input[id^="f"]');
  474. if (fld && !fld.hasClass('se_type-date')) {
  475. fld.focus();
  476. fld.keydown(function(event) {
  477. if (event.which == 13) {
  478. event.preventDefault();
  479. _inlineEditBox.find('form').submit();
  480. }
  481. });
  482. }
  483. },
  484. error: function(err) {
  485. console.log('err', err);
  486. }
  487. });
  488. });
  489. };
  490. Plugin.prototype.initialRender = function() {
  491. this.log('initialRender', '<?php echo __LINE__; ?>');
  492. this._filtersPanelNode = this.createFiltersPanelNode();
  493. $(this.element).append(this._filtersPanelNode);
  494. this._statsPanelNode = this.createStatsPanelNode();
  495. $(this.element).append(this._statsPanelNode);
  496. this._tableNode = $('<table></table>');
  497. this._tableNode.addClass('tbl-przypomnij');
  498. this._tableNode.addClass('table table-bordered table-hover');
  499. this.createTableHead().appendTo(this._tableNode);
  500. this._tbodyNode = $('<tbody></tbody>');
  501. this._tbodyNode.appendTo(this._tableNode);
  502. $(this.element).append(this._tableNode);
  503. this._inlineEditNode = this.createInlineEditBox();
  504. $(this.element).append(this._inlineEditNode);
  505. };
  506. Plugin.prototype.createFiltersPanelNode = function() {
  507. var self = this,
  508. filtersPanelNode = $('<div class="container" style="margin-top:8px;"></div>'),
  509. groupNode,
  510. btnNode,
  511. typeFiltersNode = $('<div class="btn-group"></div>').appendTo(filtersPanelNode),// TODO: RMME
  512. dateFiltersNode = $('<div class="btn-group"></div>').appendTo(filtersPanelNode)// TODO: RMME
  513. ;
  514. $.each(this._filters, function(fltrType, fltrItems) {
  515. self._filterNodes[fltrType] = {};
  516. groupNode = $('<div class="btn-group"></div>').appendTo(filtersPanelNode);
  517. var icon = self.options.filters[fltrType].icon;
  518. btnNode = $('<button class="btn btn-default" title="Filtr"><i class="glyphicon glyphicon-' + icon + '"></i></button>');
  519. btnNode.appendTo(groupNode);
  520. $.each(fltrItems, function(itemName, isActive) {
  521. btnNode = $('<button class="btn btn-default"></button>');
  522. btnNode.data('type', fltrType);
  523. btnNode.data('name', itemName);
  524. if (self.options.filters[fltrType]['itemTitles'][itemName]) {
  525. btnNode.attr('title', self.options.filters[fltrType]['itemTitles'][itemName]);
  526. }
  527. if (true === self._filters[fltrType][itemName]) {
  528. btnNode.addClass('active');
  529. }
  530. btnNode.text(self.options.filters[fltrType]['labels'][itemName]);
  531. //btnNode.html(self.options.filters[fltrType]['labels'][itemName] + ' <span class="badge" style="background-color: #aaa;">3</span>');// TODO: TEST badge
  532. btnNode.appendTo(groupNode);
  533. btnNode.on('click', function(e) {
  534. self.onClickFilter(e);
  535. });
  536. self._filterNodes[fltrType][itemName] = btnNode;
  537. });
  538. btnNode = $('<button class="btn btn-default disabled" title="Kasuj filtr do ustawień domyślnych"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(groupNode);
  539. btnNode.on('click', function(e) {
  540. self.onClickRestoreFilters(e, fltrType);
  541. });
  542. self._filterNodes[fltrType]['RESTORE_DEFAULT'] = btnNode;
  543. filtersPanelNode.append(document.createTextNode(' '));
  544. });
  545. return filtersPanelNode;
  546. };
  547. Plugin.prototype.createStatsPanelNode = function() {
  548. var statsPanelNode = $('<div class="container" style="margin-top:8px;margin-bottom:8px"></div>'),
  549. self = this,
  550. stats = {}
  551. ;
  552. stats['projekt'] = 0;
  553. stats['koresp'] = 0;
  554. stats['proces'] = 0;
  555. stats['task'] = 0;
  556. this.log('createStatsPanelNode', '<?php echo __LINE__; ?>', [this._filters]);
  557. $.each(this._tasks, function(idx, task) {
  558. if (!stats.hasOwnProperty(task._task_type)) {
  559. self.log('BUG stats has no property "'+task._task_type+'"', '<?php echo __LINE__; ?>', task);
  560. return;
  561. }
  562. if (!self.isTaskVisible(task)) {
  563. return;
  564. }
  565. var typeName = task._task_type.toUpperCase();
  566. if (self._filters['type'].hasOwnProperty(typeName)
  567. && true === self._filters['type'][typeName]) {
  568. } else {
  569. return;
  570. }
  571. var hasActiveFilter = false;
  572. $.each(self._filters['date'], function(itemName, isActive) {
  573. if (isActive) {
  574. if (task._l_app_class == 'date-' + itemName) {
  575. hasActiveFilter = true;
  576. }
  577. }
  578. });
  579. if (hasActiveFilter) {
  580. stats[task._task_type] += 1;
  581. }
  582. });
  583. $('<span>Ilość pism: ' + stats['projekt'] + ', </span>').appendTo(statsPanelNode);
  584. $('<span>ilość spraw: ' + stats['koresp'] + ', </span>').appendTo(statsPanelNode);
  585. $('<span>ilość procesów: ' + stats['proces'] + ', </span>').appendTo(statsPanelNode);
  586. $('<span>ilość zadań: ' + stats['task'] + '.</span>').appendTo(statsPanelNode);
  587. if (!stats['projekt'] && !stats['koresp'] && !stats['proces'] && !stats['task']) {
  588. $('<div class="alert alert-warning">Brak danych pasujących do wybranego filtra</div>').appendTo(statsPanelNode);
  589. }
  590. return statsPanelNode;
  591. };
  592. Plugin.prototype.onClickRestoreFilters = function(e, fltrType) {
  593. var self = this,
  594. n = $(e.target)
  595. ;
  596. this.log('onClickRestoreFilters', '<?php echo __LINE__; ?>', {fltrType: fltrType});
  597. $.each(this._filters[fltrType], function(itemName, isActive) {
  598. self._filters[fltrType][itemName] = self.options.filters[fltrType]['isActive'][itemName];
  599. });
  600. n.blur();
  601. this._afterUpdateFilters();
  602. };
  603. Plugin.prototype.onClickFilter = function(e) {
  604. var n = $(e.target),
  605. type = n.data('type'),
  606. name = n.data('name')
  607. ;
  608. this.log('onClickFilter', '<?php echo __LINE__; ?>', [n.data('type'), n.data('name'), n, e]);
  609. if (!type || !name || undefined === this._filters[type][name]) return;
  610. this._filters[type][name] = !this._filters[type][name];
  611. n.blur();
  612. this._afterUpdateFilters();
  613. };
  614. Plugin.prototype._afterUpdateFilters = function() {
  615. var self = this;
  616. this.log('_afterUpdateFilters', '<?php echo __LINE__; ?>');
  617. $.each(this._filters, function(fltrType, fltrItems) {
  618. var isDiffToDefault = false;
  619. $.each(fltrItems, function(itemName, isActive) {
  620. if (self.options.filters[fltrType]['isActive'][itemName] !== isActive) {
  621. isDiffToDefault = true;
  622. }
  623. var n = self._filterNodes[fltrType][itemName];
  624. if (isActive) {
  625. n.addClass('active');
  626. self._tableNode.removeClass('fltr-hide_' + itemName);
  627. } else {
  628. n.removeClass('active');
  629. self._tableNode.addClass('fltr-hide_' + itemName);
  630. }
  631. });
  632. var btnRestoreDefault = self._filterNodes[fltrType]['RESTORE_DEFAULT'];
  633. if (isDiffToDefault) {
  634. btnRestoreDefault.removeClass('disabled');
  635. } else {
  636. btnRestoreDefault.addClass('disabled');
  637. }
  638. });
  639. this.renderStatsPanel();
  640. };
  641. Plugin.prototype.updateTask = function(task_type, task_rowid, newTask) {
  642. this.log('updateTask', '<?php echo __LINE__; ?>', {task_type: task_type, ID: task_rowid, newTask: newTask});
  643. var taskIdx,
  644. task,
  645. taskChanged = false
  646. ;
  647. try {
  648. taskIdx = this._sortedTasks[task_type][task_rowid];
  649. task = this._tasks[taskIdx];
  650. this.log('updateTask task', '<?php echo __LINE__; ?>', {task: task});
  651. if (task) {
  652. if (newTask.hasOwnProperty('L_APPOITMENT_INFO') && newTask.L_APPOITMENT_INFO != task.L_APPOITMENT_INFO) {
  653. task.L_APPOITMENT_INFO = newTask.L_APPOITMENT_INFO;
  654. taskChanged = true;
  655. }
  656. if (newTask.hasOwnProperty('L_APPOITMENT_DATE') && newTask.L_APPOITMENT_DATE != task.L_APPOITMENT_DATE) {
  657. task.L_APPOITMENT_DATE = newTask.L_APPOITMENT_DATE;
  658. taskChanged = true;
  659. }
  660. if (newTask.hasOwnProperty('_l_app_date') && newTask._l_app_date != task._l_app_date) {
  661. task._l_app_date = newTask._l_app_date;
  662. taskChanged = true;
  663. }
  664. if (newTask.hasOwnProperty('L_APPOITMENT_USER') && newTask.L_APPOITMENT_USER != task.L_APPOITMENT_USER) {
  665. task.L_APPOITMENT_USER = newTask.L_APPOITMENT_USER;
  666. taskChanged = true;
  667. }
  668. if (newTask.hasOwnProperty('_l_app') && newTask._l_app != task._l_app) {
  669. task._l_app = newTask._l_app;
  670. taskChanged = true;
  671. }
  672. if (newTask.hasOwnProperty('_l_app_class') && newTask._l_app_class != task._l_app_class) {
  673. task._l_app_class = newTask._l_app_class;
  674. taskChanged = true;
  675. }
  676. this.log('updateTask task taskChanged', '<?php echo __LINE__; ?>', {task: task, taskChanged: taskChanged, taskStored: this._tasks[taskIdx]});
  677. }
  678. } catch(e) {
  679. this.log('error', '<?php echo __LINE__; ?>', e);
  680. }
  681. if (taskChanged) {
  682. this._needRender['TableBody'] = taskIdx;
  683. this._needRender['StatsPanel'] = true;
  684. this.render();
  685. }
  686. };
  687. Plugin.prototype.renderStatsPanel = function(value) {
  688. var statsPanelNode = this.createStatsPanelNode();
  689. this._statsPanelNode.replaceWith(statsPanelNode);
  690. this._statsPanelNode = statsPanelNode;
  691. };
  692. Plugin.prototype.createInlineEditBox = function() {
  693. var inlineEditBoxNode = $('<div class="inlineEditBox modal fade" role="dialog" aria-labelledby="przypomnijModalLabel" aria-hidden="true"></div>'),
  694. modalDialog = $('<div class="modal-dialog"></div>').appendTo(inlineEditBoxNode),
  695. modalContent = $('<div class="modal-content"></div>').appendTo(modalDialog),
  696. form = $('<form style="margin:0;padding:0;"></form>').appendTo(modalContent),
  697. modalHeader = $('<div class="modal-header"></div>').appendTo(form),
  698. headCloseBtn = $('<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(modalHeader),
  699. headLabel = $('<h3 id="przypomnijModalLabel">Edytuj</h3>').appendTo(modalHeader),
  700. modalBody = $('<div class="modal-body"></div>').appendTo(form),
  701. fldRowId = $('<input type="hidden" name="rowid" value="">').appendTo(modalBody),
  702. fldType = $('<input type="hidden" name="type" value="">').appendTo(modalBody),
  703. inlineContent = $('<div class="inlineEditBox-cnt"></div>').appendTo(modalBody),
  704. modalFooter = $('<div class="modal-footer"></div>').appendTo(form),
  705. footerCloseBtn = $('<button class="btn" data-dismiss="modal" aria-hidden="true">Zamknij</button>').appendTo(modalFooter),
  706. footerSubmitBtn = $('<input type="submit" value="Zapisz" class="btn btn-primary btn-save">').appendTo(modalFooter)
  707. ;
  708. return inlineEditBoxNode;
  709. };
  710. Plugin.prototype.isTaskVisible = function(task) {
  711. if (task._show !== true) {
  712. return false;
  713. }
  714. if (task._visible !== true) {
  715. return false;
  716. }
  717. return true;
  718. };
  719. Plugin.prototype.log = function(msg, code, variables) {
  720. var code = code || 0,
  721. variables = variables || undefined;
  722. if (this.options.debug && console && 'function' == typeof console.log) {
  723. console.log(this._name + '#' + code + ':' + msg, variables);
  724. }
  725. };
  726. $.fn[pluginName] = function(options) {
  727. return this.each(function() {
  728. if (!$.data(this, 'plugin_' + pluginName)) {
  729. $.data(this, 'plugin_' + pluginName,
  730. new Plugin(this, options));
  731. }
  732. });
  733. }
  734. })(jQuery, window, document);
  735. </script>
  736. <script>
  737. jQuery(document).ready(function() {
  738. jQuery('#przypomnij-widget').Przypomnij({
  739. debug: false,
  740. filters: <?php echo json_encode($filters); ?>,
  741. tasks: <?php echo json_encode($tasks); ?>
  742. });
  743. });
  744. </script>
  745. <?php
  746. }
  747. public function ajaxInlineEditAction() {
  748. // $_GET [rowid] => 2286, [type] => proces
  749. $przypomnij = $this->getModel();
  750. $przypomnij->sendAjaxEditAppDateInline();
  751. }
  752. public function ajaxSaveInlineEditAction() {
  753. // $_GET [rowid] => 2286, [type] => proces, [fldId] => date
  754. $przypomnij = $this->getModel();
  755. $przypomnij->sendAjaxEditAppDateInlineSave();
  756. }
  757. }