Advertisement
Guest User

task-edit-header.js

a guest
Nov 6th, 2017
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.10 KB | None | 0 0
  1. /**
  2. * Copyright (C) 2005-2013 Alfresco Software Limited.
  3. *
  4. * This file is part of Alfresco
  5. *
  6. * Alfresco is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Alfresco is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19.  
  20. /**
  21. * TaskEditHeader component.
  22. *
  23. * @namespace Alfresco.component
  24. * @class Alfresco.component.TaskEditHeader
  25. */
  26. (function()
  27. {
  28. /**
  29. * YUI Library aliases
  30. */
  31. var Dom = YAHOO.util.Dom,
  32. Event = YAHOO.util.Event,
  33. Selector = YAHOO.util.Selector;
  34.  
  35. /**
  36. * Alfresco Slingshot aliases
  37. */
  38. var $html = Alfresco.util.encodeHTML,
  39. $hasEventInterest = Alfresco.util.hasEventInterest,
  40. $siteURL = Alfresco.util.siteURL;
  41.  
  42. /**
  43. * TaskEditHeader constructor.
  44. *
  45. * @param {String} htmlId The HTML id of the parent element
  46. * @return {Alfresco.component.TaskEditHeader} The new TaskEditHeader instance
  47. * @constructor
  48. */
  49. Alfresco.component.TaskEditHeader = function TaskEditHeader_constructor(htmlId)
  50. {
  51. Alfresco.component.TaskEditHeader.superclass.constructor.call(this, htmlId, ["button"]);
  52.  
  53. // Re-register with our own name
  54. this.name = "Alfresco.component.TaskEditHeader";
  55.  
  56. // Instance variables
  57. this.options = YAHOO.lang.merge(this.options, Alfresco.component.TaskEditHeader.superclass.options);
  58. Alfresco.util.ComponentManager.reregister(this);
  59. this.isRunning = false;
  60. this.taskId = null;
  61.  
  62. /* Decoupled event listeners */
  63. YAHOO.Bubbling.on("taskDetailedData", this.onTaskDetailedData, this);
  64.  
  65. return this;
  66. };
  67.  
  68. YAHOO.extend(Alfresco.component.TaskEditHeader, Alfresco.component.ShareFormManager,
  69. {
  70.  
  71. /**
  72. * Keeps track if this component is running an action or not
  73. *
  74. * @property isRunning
  75. * @type Boolean
  76. */
  77. isRunning: false,
  78.  
  79. /**
  80. * The task instance id
  81. *
  82. * @property taskId
  83. * @type String
  84. */
  85. taskId: null,
  86.  
  87. /**
  88. * The referrer value query string parameter
  89. *
  90. * @property referrerValue
  91. * @type String
  92. */
  93. referrerValue: null,
  94.  
  95. /**
  96. * Fired by YUI when parent element is available for scripting.
  97. * Template initialisation, including instantiation of YUI widgets and event listener binding.
  98. *
  99. * @method onReady
  100. */
  101. onReady: function TEH_onReady()
  102. {
  103. // Load in the People Finder component from the server
  104. Alfresco.util.Ajax.request(
  105. {
  106. url: Alfresco.constants.URL_SERVICECONTEXT + "components/people-finder/people-finder",
  107. dataObj:
  108. {
  109. htmlid: this.id + "-peopleFinder"
  110. },
  111. successCallback:
  112. {
  113. fn: this.onPeopleFinderLoaded,
  114. scope: this
  115. },
  116. failureMessage: "Could not load People Finder component",
  117. execScripts: true
  118. });
  119.  
  120. // Format dates (datatype could be 'date' or 'datetime')
  121. var dateEls = document.querySelectorAll('[data-datatype^="date"]');
  122. for (var i = 0; i < dateEls.length; i++) {
  123. var formatString = 'date-format.default'; // Default to date time format
  124. if (dateEls[i].getAttribute('data-datatype') === 'date') {
  125. formatString = 'date-format.mediumDate';
  126. }
  127. dateEls[i].innerHTML = Alfresco.util.formatDate(dateEls[i].innerHTML, Alfresco.util.message(formatString));
  128. };
  129.  
  130. },
  131.  
  132. /**
  133. * Called when the people finder template has been loaded.
  134. * Creates a dialog and inserts the people finder for choosing assignees.
  135. *
  136. * @method onPeopleFinderLoaded
  137. * @param response The server response
  138. */
  139. onPeopleFinderLoaded: function TEH_onPeopleFinderLoaded(response)
  140. {
  141. // Inject the component from the XHR request into it's placeholder DIV element
  142. var finderDiv = Dom.get(this.id + "-peopleFinder");
  143. finderDiv.innerHTML = response.serverResponse.responseText;
  144.  
  145. // Create the Assignee dialog
  146. this.widgets.reassignPanel = Alfresco.util.createYUIPanel(this.id + "-reassignPanel");
  147.  
  148. // Find the People Finder by container ID
  149. this.widgets.peopleFinder = Alfresco.util.ComponentManager.get(this.id + "-peopleFinder");
  150.  
  151. // Set the correct options for our use
  152. this.widgets.peopleFinder.setOptions(
  153. {
  154. singleSelectMode: true,
  155. addButtonLabel: this.msg("button.select")
  156. });
  157.  
  158. // Make sure we listen for events when the user selects a person
  159. YAHOO.Bubbling.on("personSelected", this.onPersonSelected, this);
  160. },
  161.  
  162. /**
  163. * Called when the user has selected an assigne from the people finder.
  164. *
  165. * @method onPersonSelected
  166. * @param e DomEvent
  167. * @param args Event parameters (depends on event type)
  168. */
  169. onPersonSelected: function TEH_onPersonSelected(e, args)
  170. {
  171. // This is a "global" event so we ensure the event is for the current panel by checking panel visibility.
  172. if ($hasEventInterest(this.widgets.peopleFinder, args))
  173. {
  174. this.widgets.reassignPanel.hide();
  175. this._updateTaskProperties(
  176. {
  177. "cm_owner": args[1].userName
  178. }, "reassign");
  179. }
  180. },
  181.  
  182. /**
  183. * Event handler called when the "taskDetailedData" event is received
  184. *
  185. * @method: onTaskDetailedData
  186. */
  187. onTaskDetailedData: function TEH_onTaskDetailedData(layer, args)
  188. {
  189. var task = args[1];
  190.  
  191. // Save task id so we can use it when invoking actions later
  192. this.taskId = task.id;
  193.  
  194. // Save the referrer value
  195. this.referrerValue = Alfresco.util.getQueryStringParameter('referrer');
  196.  
  197. // Display actions and create yui buttons
  198. Selector.query("h1 span", this.id, true).innerHTML = $html(task.title);
  199.  
  200. // ALF-13115 fix, inform user that this task has been completed
  201. if (!task.isEditable)
  202. {
  203. Alfresco.util.PopupManager.displayMessage(
  204. {
  205. text: this.msg("message.task.completed"),
  206. displayTime: 2
  207. });
  208.  
  209. YAHOO.lang.later(2000, this, function()
  210. {
  211. // Check referrer and fall back to user dashboard if unavailable.
  212. if(this.referrerValue)
  213. {
  214. if(this.referrerValue == 'tasks')
  215. {
  216. document.location.href = $siteURL("my-tasks");
  217. }
  218. else if(this.referrerValue='workflows')
  219. {
  220. document.location.href = $siteURL("my-workflows");
  221. }
  222. }
  223. else
  224. {
  225. document.location.href = this.getSiteDefaultUrl() || Alfresco.constants.URL_CONTEXT;
  226. }
  227. }, []);
  228. }
  229.  
  230. if (task.isReassignable)
  231. {
  232. Alfresco.logger("Bhuvana"+task.isReassignable);
  233. // Task is reassignable
  234. this.widgets.reassignButton = Alfresco.util.createYUIButton(this, "reassign", this.onReassignButtonClick);
  235. Dom.removeClass(Selector.query(".actions .reassign", this.id), "hidden");
  236. }
  237.  
  238. if (task.isClaimable)
  239. {
  240. // Task is claimable
  241. this.widgets.claimButton = Alfresco.util.createYUIButton(this, "claim", this.onClaimButtonClick);
  242. Dom.removeClass(Selector.query(".actions .claim", this.id), "hidden");
  243. Dom.removeClass(Selector.query(".unassigned-message", this.id), "hidden");
  244. }
  245.  
  246. if (task.isReleasable)
  247. {
  248. // Task is releasable
  249. this.widgets.releaseButton = Alfresco.util.createYUIButton(this, "release", this.onReleaseButtonClick);
  250. Dom.removeClass(Selector.query(".actions .release", this.id), "hidden");
  251. }
  252. },
  253.  
  254. /**
  255. * Event handler called when the "release" button is clicked
  256. *
  257. * @method: onReleaseButtonClick
  258. */
  259. onReleaseButtonClick: function TEH_onReleaseButtonClick(layer, args)
  260. {
  261. this._updateTaskProperties(
  262. {
  263. "cm_owner": null
  264. }, "release");
  265. },
  266.  
  267. /**
  268. * Event handler called when the "claim" button is clicked
  269. *
  270. * @method: onClaimButtonClick
  271. */
  272. onClaimButtonClick: function TEH_onClaimButtonClick(layer, args)
  273. {
  274. this._updateTaskProperties(
  275. {
  276. "cm_owner": Alfresco.constants.USERNAME
  277. }, "claim");
  278. },
  279.  
  280. /**
  281. * Event handler called when the "reassign" button is clicked
  282. *
  283. * @method: onReassignButtonClick
  284. */
  285. onReassignButtonClick: function TEH_onReassignButtonClick(layer, args)
  286. {
  287. Alfresco.logger("Bhuvana args"+args[0]);
  288. this.widgets.peopleFinder.clearResults();
  289. this.widgets.reassignPanel.show();
  290. },
  291.  
  292. /**
  293. * Updates a task property
  294. *
  295. * @method: _updateTaskProperties
  296. * @private
  297. */
  298. _updateTaskProperties: function TEH__updateTaskProperties(properties, action)
  299. {
  300. this._disableActionButtons(true);
  301. YAHOO.lang.later(2000, this, function()
  302. {
  303. if (this.isRunning)
  304. {
  305. if (!this.widgets.feedbackMessage)
  306. {
  307. this.widgets.feedbackMessage = Alfresco.util.PopupManager.displayMessage(
  308. {
  309. text: this.msg("message." + action),
  310. spanClass: "wait",
  311. displayTime: 0
  312. });
  313. }
  314. else if (!this.widgets.feedbackMessage.cfg.getProperty("visible"))
  315. {
  316. this.widgets.feedbackMessage.show();
  317. }
  318. }
  319. }, []);
  320.  
  321. // Run rules for folder (and sub folders)
  322. if (!this.isRunning)
  323. {
  324. this.isRunning = true;
  325.  
  326. // Start/stop inherit rules from parent folder
  327. Alfresco.util.Ajax.jsonPut(
  328. {
  329. url: Alfresco.constants.PROXY_URI_RELATIVE + "api/task-instances/" + this.taskId,
  330. dataObj: properties,
  331. successCallback:
  332. {
  333. fn: function(response, action)
  334. {
  335. this.isRunning = false;
  336. var data = response.json.data;
  337. if (data)
  338. {
  339. Alfresco.util.PopupManager.displayMessage(
  340. {
  341. text: this.msg("message." + action + ".success")
  342. });
  343.  
  344. YAHOO.lang.later(3000, this, function(data)
  345. {
  346. if (data.owner && data.owner.userName == Alfresco.constants.USERNAME)
  347. {
  348. // MNT-11418: Save previous URL
  349. if (YAHOO.env.ua.chrome > 0)
  350. {
  351. var prevUrl = (history.state && history.state.previous_url) ? history.state.previous_url : document.referrer;
  352. var currUrl = document.location.href;
  353. if (prevUrl && prevUrl != "")
  354. {
  355. history.pushState({'previous_url': prevUrl, 'current_url': currUrl}, document.title, "");
  356. }
  357. }
  358. // Let the user keep working on the task since he claimed it
  359. document.location.reload();
  360. }
  361. else
  362. {
  363. // Check referrer and fall back to user dashboard if unavailable.
  364. if(this.referrerValue)
  365. {
  366. // MNT-10182. The user may not have rights to see task details any more.
  367. if (this.referrerValue == 'tasks')
  368. {
  369. document.location.href = $siteURL("my-tasks");
  370. }
  371. else
  372. {
  373. // Take the user to the most suitable place
  374. this.navigateForward(true);
  375. }
  376. } else {
  377. // ALF-20001. If referrer isn't available, either because there was no previous page
  378. // (because the user navigated directly to the page via an emailed link)
  379. // or because the referrer header has been blocked, fall back to user dashboard.
  380. document.location.href = this.getSiteDefaultUrl() || Alfresco.constants.URL_CONTEXT;
  381. }
  382. }
  383. }, data);
  384.  
  385. }
  386. },
  387. obj: action,
  388. scope: this
  389. },
  390. failureCallback:
  391. {
  392. fn: function(response)
  393. {
  394. this.isRunning = false;
  395. this._disableActionButtons(false);
  396. Alfresco.util.PopupManager.displayPrompt(
  397. {
  398. title: this.msg("message.failure"),
  399. text: this.msg("message." + action + ".failure")
  400. });
  401. },
  402. scope: this
  403. }
  404. });
  405. }
  406. },
  407.  
  408. _disableActionButtons: function(disabled)
  409. {
  410. if (this.widgets.reassignButton)
  411. {
  412. this.widgets.reassignButton.set("disabled", disabled)
  413. }
  414. if (this.widgets.releaseButton)
  415. {
  416. this.widgets.releaseButton.set("disabled", disabled)
  417. }
  418. if (this.widgets.claimButton)
  419. {
  420. this.widgets.claimButton.set("disabled", disabled)
  421. }
  422. }
  423.  
  424. });
  425. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement