Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.67 KB | None | 0 0
  1. /**
  2. * Copyright (C) 2005-2014 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. * Dashboard Activities common component.
  22. *
  23. * @namespace Alfresco.dashlet
  24. * @class Alfresco.dashlet.Activities
  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. * Preferences
  37. */
  38. var PREFERENCES_ACTIVITIES = "org.alfresco.share.activities",
  39. PREF_FILTER = ".filter",
  40. PREF_RANGE = ".range",
  41. PREF_ACTIVITIES = ".activities";
  42.  
  43. /**
  44. * Dashboard Activities constructor.
  45. *
  46. * @param {String} htmlId The HTML id of the parent element
  47. * @return {Alfresco.dashlet.Activities} The new component instance
  48. * @constructor
  49. */
  50. Alfresco.dashlet.Activities = function Activities_constructor(htmlId)
  51. {
  52. Alfresco.dashlet.Activities.superclass.constructor.call(this, "Alfresco.dashlet.Activities", htmlId, ["button", "container", "calendar"]);
  53.  
  54. // Preferences service
  55. this.services.preferences = new Alfresco.service.Preferences();
  56.  
  57. return this;
  58. };
  59.  
  60. YAHOO.extend(Alfresco.dashlet.Activities, Alfresco.component.Base,
  61. {
  62. /**
  63. * Object container for initialization options
  64. *
  65. * @property options
  66. * @type object
  67. */
  68. options:
  69. {
  70. /**
  71. * Dashlet mode
  72. *
  73. * @property mode
  74. * @type string
  75. * @default "site"
  76. */
  77. mode: "site",
  78.  
  79. /**
  80. * Current siteId.
  81. *
  82. * @property siteId
  83. * @type string
  84. */
  85. siteId: "",
  86.  
  87. /**
  88. * Currently active filter.
  89. *
  90. * @property activeFilter
  91. * @type string
  92. * @default "today"
  93. */
  94. activeFilter: "today",
  95.  
  96. /**
  97. * Component region ID.
  98. *
  99. * @property regionId
  100. * @type string
  101. */
  102. regionId: ""
  103. },
  104.  
  105. /**
  106. * Activity list DOM container.
  107. *
  108. * @property activityList
  109. * @type object
  110. */
  111. activityList: null,
  112.  
  113. /**
  114. * URL to the RSS feed
  115. *
  116. * @property link
  117. * @type String
  118. */
  119. link: "",
  120.  
  121. /**
  122. * Fired by YUI when parent element is available for scripting
  123. * @method onReady
  124. */
  125. onReady: function Activities_onReady()
  126. {
  127. var me = this;
  128.  
  129. // Create dropdown filter widgets
  130. this.widgets.range = Alfresco.util.createYUIButton(this, "range", this.onDateFilterChanged,
  131. {
  132. type: "menu",
  133. menu: "range-menu",
  134. lazyloadmenu: false
  135. });
  136.  
  137. this.widgets.user = Alfresco.util.createYUIButton(this, "user", this.onExclusionFilterChanged,
  138. {
  139. type: "menu",
  140. menu: "user-menu",
  141. lazyloadmenu: false
  142. });
  143.  
  144. this.widgets.activities = Alfresco.util.createYUIButton(this, "activities", this.onActivitiesFilterChanged,
  145. {
  146. type: "menu",
  147. menu: "activities-menu",
  148. lazyloadmenu: false
  149. });
  150.  
  151. // The activity list container
  152. this.activityList = Dom.get(this.id + "-activityList");
  153.  
  154. // Load preferences to override default filter and range
  155. this.widgets.range.set("label", this.msg("filter.7days"));
  156. this.widgets.range.value = "7";
  157. this.widgets.user.set("label", this.msg("filter.all"));
  158. this.widgets.user.value = "all";
  159. this.widgets.activities.set("label", this.msg("filter.allItems") + " " + Alfresco.constants.MENU_ARROW_SYMBOL);
  160. this.widgets.activities.value = "";
  161.  
  162. var prefs = this.services.preferences.get();
  163. var activitiesPreference = Alfresco.util.findValueByDotNotation(prefs, this.buildPreferences(PREF_ACTIVITIES), "");
  164. if (activitiesPreference !== null)
  165. {
  166. this.widgets.activities.value = activitiesPreference;
  167. // set the correct menu label
  168. var menuItems = this.widgets.activities.getMenu().getItems();
  169. for (index in menuItems)
  170. {
  171. if (menuItems.hasOwnProperty(index))
  172. {
  173. if (menuItems[index].value === activitiesPreference)
  174. {
  175. this.widgets.activities.set("label", menuItems[index].cfg.getProperty("text") + " " + Alfresco.constants.MENU_ARROW_SYMBOL);
  176. break;
  177. }
  178. }
  179. }
  180. }
  181.  
  182. var rangePreference = Alfresco.util.findValueByDotNotation(prefs, this.buildPreferences(PREF_RANGE), "7");
  183. if (rangePreference !== null)
  184. {
  185. this.widgets.range.value = rangePreference;
  186. // set the correct menu label
  187. var menuItems = this.widgets.range.getMenu().getItems();
  188. for (index in menuItems)
  189. {
  190. if (menuItems.hasOwnProperty(index))
  191. {
  192. if (menuItems[index].value === rangePreference)
  193. {
  194. this.widgets.range.set("label", menuItems[index].cfg.getProperty("text") + " " + Alfresco.constants.MENU_ARROW_SYMBOL);
  195. break;
  196. }
  197. }
  198. }
  199. }
  200.  
  201. var filterPreference = Alfresco.util.findValueByDotNotation(prefs, this.buildPreferences(PREF_FILTER), "all");
  202. if (filterPreference !== null)
  203. {
  204. this.widgets.user.value = filterPreference;
  205. // set the correct menu label
  206. var menuItems = this.widgets.user.getMenu().getItems();
  207. for (index in menuItems)
  208. {
  209. if (menuItems.hasOwnProperty(index))
  210. {
  211. if (menuItems[index].value === filterPreference)
  212. {
  213. this.widgets.user.set("label", menuItems[index].cfg.getProperty("text") + " " + Alfresco.constants.MENU_ARROW_SYMBOL);
  214. break;
  215. }
  216. }
  217. }
  218. }
  219.  
  220. // Display the toolbar now that we have selected the filter
  221. Dom.removeClass(Selector.query(".toolbar div", this.id, true), "hidden");
  222. // Populate the activity list
  223. this.populateActivityList(this.widgets.range.value, this.widgets.user.value, this.widgets.activities.value);
  224. },
  225.  
  226. /**
  227. * Build the Activities dashlet preferences name string with optional suffix.
  228. * The component region ID and the current siteId (if any) is used as part of the
  229. * preferences name - to uniquely identify the preference within the site or user
  230. * dashboard context.
  231. *
  232. * @method buildPreferences
  233. * @param suffix {string} optional suffix to append to the preferences name
  234. */
  235. buildPreferences: function Activities_buildPreferences(suffix)
  236. {
  237. var opt = this.options;
  238. return PREFERENCES_ACTIVITIES + "." + opt.regionId + (opt.siteId ? ("." + opt.siteId) : "") + (suffix ? suffix : "");
  239. },
  240.  
  241. /**
  242. * Populate the activity list via Ajax request
  243. * @method populateActivityList
  244. */
  245. populateActivityList: function Activities_populateActivityList(dateFilter, userFilter, activityFilter)
  246. {
  247. // Load the activity list
  248. Alfresco.util.Ajax.request(
  249. {
  250. url: Alfresco.constants.URL_SERVICECONTEXT + "components/dashlets/activities/list",
  251. dataObj:
  252. {
  253. site: this.options.siteId,
  254. mode: this.options.mode,
  255. dateFilter: dateFilter,
  256. userFilter: userFilter,
  257. activityFilter: activityFilter
  258. },
  259. successCallback:
  260. {
  261. fn: this.onListLoaded,
  262. scope: this,
  263. obj: dateFilter
  264. },
  265. failureCallback:
  266. {
  267. fn: this.onListLoadFailed,
  268. scope: this
  269. },
  270. scope: this,
  271. noReloadOnAuthFailure: true
  272. });
  273. },
  274.  
  275. /**
  276. * List loaded successfully
  277. * @method onListLoaded
  278. * @param p_response {object} Response object from request
  279. */
  280. onListLoaded: function Activities_onListLoaded(p_response, p_obj)
  281. {
  282. this.options.activeFilter = p_obj;
  283. var html = p_response.serverResponse.responseText;
  284. if (YAHOO.lang.trim(html).length === 0)
  285. {
  286. this.activityList.innerHTML = Dom.get(this.id + "-empty").innerHTML;
  287. }
  288. else
  289. {
  290. this.activityList.innerHTML = html;
  291. Dom.getElementsByClassName("relativeTime", "span", this.activityList, function()
  292. {
  293. this.innerHTML = Alfresco.util.relativeTime(this.innerHTML);
  294. })
  295. var olderDates = this.msg("label.older-activities"),
  296. lastDay = "";
  297. Dom.getElementsByClassName("relativeDate", "span", this.activityList, function()
  298. {
  299. Dom.addClass(this, "body");
  300.  
  301. // Get the relative Date
  302. var activityDay = Alfresco.util.relativeDate(this.innerHTML,
  303. {
  304. olderDates: olderDates
  305. });
  306.  
  307. // if the relativeDate is not the same as it was last time, output it and update the last day found.
  308. if (activityDay !== lastDay)
  309. {
  310. this.innerHTML = activityDay;
  311. lastDay = activityDay;
  312. }
  313. else
  314. {
  315. // if the relative date is the same, remove the element that separates the days
  316. var parent = this.parentNode;
  317. parent.parentNode.removeChild(parent);
  318. }
  319. })
  320. }
  321. this.updateFeedLink(this.widgets.range.value, this.widgets.user.value, this.widgets.activities.value);
  322. },
  323.  
  324. /**
  325. * List load failed
  326. * @method onListLoadFailed
  327. */
  328. onListLoadFailed: function Activities_onListLoadFailed()
  329. {
  330. this.activityList.innerHTML = '<div class="detail-list-item first-item last-item">' + this.msg("label.load-failed") + '</div>';
  331. },
  332.  
  333. /**
  334. * Sets the the feed link
  335. * @method updateFeedLink
  336. */
  337. updateFeedLink: function Activities_updateFeedLink(dateFilter,userFilter,activityFilter)
  338. {
  339. var url = Alfresco.constants.URL_FEEDSERVICECONTEXT + "components/dashlets/activities/list?";
  340. var dataObj =
  341. {
  342. format: "atomfeed",
  343. mode: this.options.mode,
  344. site: this.options.siteId,
  345. dateFilter: dateFilter,
  346. userFilter: userFilter,
  347. activityFilter: activityFilter
  348. };
  349. url += Alfresco.util.Ajax.jsonToParamString(dataObj, true);
  350. this.link = url;
  351. },
  352.  
  353. openFeedLink: function Activities_openFeedLink()
  354. {
  355. window.open(this.link);
  356. },
  357.  
  358. /**
  359. * YUI WIDGET EVENT HANDLERS
  360. * Handlers for standard events fired from YUI widgets, e.g. "click"
  361. */
  362.  
  363. /**
  364. * Date drop-down changed event handler
  365. *
  366. * @method onDateFilterChanged
  367. * @param p_sType {string} The event
  368. * @param p_aArgs {array} Event arguments
  369. */
  370. onDateFilterChanged: function Activities_onDateFilterChanged(p_sType, p_aArgs)
  371. {
  372. var menuItem = p_aArgs[1];
  373.  
  374. if (menuItem)
  375. {
  376. this.widgets.range.set("label", menuItem.cfg.getProperty("text") + " " + Alfresco.constants.MENU_ARROW_SYMBOL);
  377. this.widgets.range.value = menuItem.value;
  378. this.populateActivityList(this.widgets.range.value, this.widgets.user.value, this.widgets.activities.value);
  379. this.services.preferences.set(this.buildPreferences(PREF_RANGE), this.widgets.range.value);
  380. }
  381. },
  382.  
  383. /**
  384. * Exclusion drop-down changed event handler
  385. *
  386. * @method onExclusionFilterChanged
  387. * @param p_sType {string} The event
  388. * @param p_aArgs {array} Event arguments
  389. */
  390. onExclusionFilterChanged: function Activities_onExclusionFilterChanged(p_sType, p_aArgs)
  391. {
  392. var menuItem = p_aArgs[1];
  393.  
  394. if (menuItem)
  395. {
  396. this.widgets.user.set("label", menuItem.cfg.getProperty("text") + " " + Alfresco.constants.MENU_ARROW_SYMBOL);
  397. this.widgets.user.value = menuItem.value;
  398. this.populateActivityList(this.widgets.range.value, this.widgets.user.value, this.widgets.activities.value);
  399. this.services.preferences.set(this.buildPreferences(PREF_FILTER), this.widgets.user.value);
  400. }
  401. },
  402.  
  403. /**
  404. * Activities drop-down changed event handler
  405. *
  406. * @method onActivitiesFilterChanged
  407. * @param p_sType {string} The event
  408. * @param p_aArgs {array} Event arguments
  409. */
  410. onActivitiesFilterChanged: function Activities_onActivitiesFilterChanged(p_sType, p_aArgs)
  411. {
  412. var menuItem = p_aArgs[1];
  413.  
  414. if (menuItem)
  415. {
  416. this.widgets.activities.set("label", menuItem.cfg.getProperty("text") + " " + Alfresco.constants.MENU_ARROW_SYMBOL);
  417. this.widgets.activities.value = menuItem.value;
  418. this.populateActivityList(this.widgets.range.value, this.widgets.user.value, this.widgets.activities.value);
  419. this.services.preferences.set(this.buildPreferences(PREF_ACTIVITIES), this.widgets.activities.value);
  420. }
  421. }
  422. });
  423. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement