FeedEntryViewer.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.atom.widget.FeedEntryViewer"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.atom.widget.FeedEntryViewer"] = true;
  8. dojo.provide("dojox.atom.widget.FeedEntryViewer");
  9. dojo.require("dojo.fx");
  10. dojo.require("dijit._Widget");
  11. dojo.require("dijit._Templated");
  12. dojo.require("dijit._Container");
  13. dojo.require("dijit.layout.ContentPane");
  14. dojo.require("dojox.atom.io.Connection");
  15. dojo.requireLocalization("dojox.atom.widget", "FeedEntryViewer", null, "ROOT,ar,az,bg,ca,cs,da,de,el,es,fi,fr,he,hr,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
  16. dojo.experimental("dojox.atom.widget.FeedEntryViewer");
  17. dojo.declare("dojox.atom.widget.FeedEntryViewer",[dijit._Widget, dijit._Templated, dijit._Container],{
  18. // summary:
  19. // An ATOM feed entry editor for publishing updated ATOM entries, or viewing non-editable entries.
  20. // description:
  21. // An ATOM feed entry editor for publishing updated ATOM entries, or viewing non-editable entries.
  22. entrySelectionTopic: "", //The topic to listen on for entries to edit.
  23. _validEntryFields: {}, //The entry fields that were present on the entry and are being displayed.
  24. //This works in conjuntion with what is selected to be displayed.
  25. displayEntrySections: "", //What current sections of the entries to display as a comma separated list.
  26. _displayEntrySections: null,
  27. //Control options for the display options menu.
  28. enableMenu: false,
  29. enableMenuFade: false,
  30. _optionButtonDisplayed: true,
  31. //Templates for the HTML rendering. Need to figure these out better, admittedly.
  32. templateString: dojo.cache("dojox.atom", "widget/templates/FeedEntryViewer.html", "<div class=\"feedEntryViewer\">\n <table border=\"0\" width=\"100%\" class=\"feedEntryViewerMenuTable\" dojoAttachPoint=\"feedEntryViewerMenu\" style=\"display: none;\">\n <tr width=\"100%\" dojoAttachPoint=\"entryCheckBoxDisplayOptions\">\n <td align=\"right\">\n <span class=\"feedEntryViewerMenu\" dojoAttachPoint=\"displayOptions\" dojoAttachEvent=\"onclick:_toggleOptions\"></span>\n </td>\n </tr>\n <tr class=\"feedEntryViewerDisplayCheckbox\" dojoAttachPoint=\"entryCheckBoxRow\" width=\"100%\" style=\"display: none;\">\n <td dojoAttachPoint=\"feedEntryCelltitle\">\n <input type=\"checkbox\" name=\"title\" value=\"Title\" dojoAttachPoint=\"feedEntryCheckBoxTitle\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelTitle\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellauthors\">\n <input type=\"checkbox\" name=\"authors\" value=\"Authors\" dojoAttachPoint=\"feedEntryCheckBoxAuthors\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelAuthors\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellcontributors\">\n <input type=\"checkbox\" name=\"contributors\" value=\"Contributors\" dojoAttachPoint=\"feedEntryCheckBoxContributors\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelContributors\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellid\">\n <input type=\"checkbox\" name=\"id\" value=\"Id\" dojoAttachPoint=\"feedEntryCheckBoxId\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelId\"></label>\n </td>\n <td rowspan=\"2\" align=\"right\">\n <span class=\"feedEntryViewerMenu\" dojoAttachPoint=\"close\" dojoAttachEvent=\"onclick:_toggleOptions\"></span>\n </td>\n\t\t</tr>\n\t\t<tr class=\"feedEntryViewerDisplayCheckbox\" dojoAttachPoint=\"entryCheckBoxRow2\" width=\"100%\" style=\"display: none;\">\n <td dojoAttachPoint=\"feedEntryCellupdated\">\n <input type=\"checkbox\" name=\"updated\" value=\"Updated\" dojoAttachPoint=\"feedEntryCheckBoxUpdated\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelUpdated\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellsummary\">\n <input type=\"checkbox\" name=\"summary\" value=\"Summary\" dojoAttachPoint=\"feedEntryCheckBoxSummary\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelSummary\"></label>\n </td>\n <td dojoAttachPoint=\"feedEntryCellcontent\">\n <input type=\"checkbox\" name=\"content\" value=\"Content\" dojoAttachPoint=\"feedEntryCheckBoxContent\" dojoAttachEvent=\"onclick:_toggleCheckbox\"/>\n\t\t\t\t<label for=\"title\" dojoAttachPoint=\"feedEntryCheckBoxLabelContent\"></label>\n </td>\n </tr>\n </table>\n \n <table class=\"feedEntryViewerContainer\" border=\"0\" width=\"100%\">\n <tr class=\"feedEntryViewerTitle\" dojoAttachPoint=\"entryTitleRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryTitleHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryTitleNode\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n\n <tr class=\"feedEntryViewerAuthor\" dojoAttachPoint=\"entryAuthorRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryAuthorHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryAuthorNode\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n\n <tr class=\"feedEntryViewerContributor\" dojoAttachPoint=\"entryContributorRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryContributorHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryContributorNode\" class=\"feedEntryViewerContributorNames\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n \n <tr class=\"feedEntryViewerId\" dojoAttachPoint=\"entryIdRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryIdHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryIdNode\" class=\"feedEntryViewerIdText\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n \n <tr class=\"feedEntryViewerUpdated\" dojoAttachPoint=\"entryUpdatedRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryUpdatedHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryUpdatedNode\" class=\"feedEntryViewerUpdatedText\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n \n <tr class=\"feedEntryViewerSummary\" dojoAttachPoint=\"entrySummaryRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entrySummaryHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entrySummaryNode\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n \n <tr class=\"feedEntryViewerContent\" dojoAttachPoint=\"entryContentRow\" style=\"display: none;\">\n <td>\n <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr class=\"graphic-tab-lgray\">\n\t\t\t\t\t\t<td class=\"lp2\">\n\t\t\t\t\t\t\t<span class=\"lp\" dojoAttachPoint=\"entryContentHeader\"></span>\n\t\t\t\t\t\t</td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryContentNode\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n </table>\n</div>\n"),
  33. _entry: null, //The entry that is being viewed/edited.
  34. _feed: null, //The feed the entry came from.
  35. _editMode: false, //Flag denoting the state of the widget, in edit mode or not.
  36. postCreate: function(){
  37. if(this.entrySelectionTopic !== ""){
  38. this._subscriptions = [dojo.subscribe(this.entrySelectionTopic, this, "_handleEvent")];
  39. }
  40. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  41. this.displayOptions.innerHTML = _nlsResources.displayOptions;
  42. this.feedEntryCheckBoxLabelTitle.innerHTML = _nlsResources.title;
  43. this.feedEntryCheckBoxLabelAuthors.innerHTML = _nlsResources.authors;
  44. this.feedEntryCheckBoxLabelContributors.innerHTML = _nlsResources.contributors;
  45. this.feedEntryCheckBoxLabelId.innerHTML = _nlsResources.id;
  46. this.close.innerHTML = _nlsResources.close;
  47. this.feedEntryCheckBoxLabelUpdated.innerHTML = _nlsResources.updated;
  48. this.feedEntryCheckBoxLabelSummary.innerHTML = _nlsResources.summary;
  49. this.feedEntryCheckBoxLabelContent.innerHTML = _nlsResources.content;
  50. },
  51. startup: function(){
  52. if(this.displayEntrySections === ""){
  53. this._displayEntrySections = ["title","authors","contributors","summary","content","id","updated"];
  54. }else{
  55. this._displayEntrySections = this.displayEntrySections.split(",");
  56. }
  57. this._setDisplaySectionsCheckboxes();
  58. if(this.enableMenu){
  59. dojo.style(this.feedEntryViewerMenu, 'display', '');
  60. if(this.entryCheckBoxRow && this.entryCheckBoxRow2){
  61. if(this.enableMenuFade){
  62. dojo.fadeOut({node: this.entryCheckBoxRow,duration: 250}).play();
  63. dojo.fadeOut({node: this.entryCheckBoxRow2,duration: 250}).play();
  64. }
  65. }
  66. }
  67. },
  68. clear: function(){
  69. // summary:
  70. // Function to clear the state of the widget.
  71. // description:
  72. // Function to clear the state of the widget.
  73. this.destroyDescendants();
  74. this._entry=null;
  75. this._feed=null;
  76. this.clearNodes();
  77. },
  78. clearNodes: function(){
  79. // summary:
  80. // Function to clear all the display nodes for the ATOM entry from the viewer.
  81. // description:
  82. // Function to clear all the display nodes for the ATOM entry from the viewer.
  83. dojo.forEach([
  84. "entryTitleRow", "entryAuthorRow", "entryContributorRow", "entrySummaryRow", "entryContentRow",
  85. "entryIdRow", "entryUpdatedRow"
  86. ], function(node){
  87. dojo.style(this[node], "display", "none");
  88. }, this);
  89. dojo.forEach([
  90. "entryTitleNode", "entryTitleHeader", "entryAuthorHeader", "entryContributorHeader",
  91. "entryContributorNode", "entrySummaryHeader", "entrySummaryNode", "entryContentHeader",
  92. "entryContentNode", "entryIdNode", "entryIdHeader", "entryUpdatedHeader", "entryUpdatedNode"
  93. ], function(part){
  94. while(this[part].firstChild){
  95. dojo.destroy(this[part].firstChild);
  96. }
  97. }
  98. ,this);
  99. },
  100. setEntry: function(/*object*/entry, /*object*/feed, /*boolean*/leaveMenuState){
  101. // summary:
  102. // Function to set the current entry that is being edited.
  103. // description:
  104. // Function to set the current entry that is being edited.
  105. //
  106. // entry:
  107. // Instance of dojox.atom.io.model.Entry to display for reading/editing.
  108. this.clear();
  109. this._validEntryFields = {};
  110. this._entry = entry;
  111. this._feed = feed;
  112. if(entry !== null){
  113. // Handle the title.
  114. if(this.entryTitleHeader){
  115. this.setTitleHeader(this.entryTitleHeader, entry);
  116. }
  117. if(this.entryTitleNode){
  118. this.setTitle(this.entryTitleNode, this._editMode, entry);
  119. }
  120. if(this.entryAuthorHeader){
  121. this.setAuthorsHeader(this.entryAuthorHeader, entry);
  122. }
  123. if(this.entryAuthorNode){
  124. this.setAuthors(this.entryAuthorNode, this._editMode, entry);
  125. }
  126. if(this.entryContributorHeader){
  127. this.setContributorsHeader(this.entryContributorHeader, entry);
  128. }
  129. if(this.entryContributorNode){
  130. this.setContributors(this.entryContributorNode, this._editMode, entry);
  131. }
  132. if(this.entryIdHeader){
  133. this.setIdHeader(this.entryIdHeader, entry);
  134. }
  135. if(this.entryIdNode){
  136. this.setId(this.entryIdNode, this._editMode, entry);
  137. }
  138. if(this.entryUpdatedHeader){
  139. this.setUpdatedHeader(this.entryUpdatedHeader, entry);
  140. }
  141. if(this.entryUpdatedNode){
  142. this.setUpdated(this.entryUpdatedNode, this._editMode, entry);
  143. }
  144. if(this.entrySummaryHeader){
  145. this.setSummaryHeader(this.entrySummaryHeader, entry);
  146. }
  147. if(this.entrySummaryNode){
  148. this.setSummary(this.entrySummaryNode, this._editMode, entry);
  149. }
  150. if(this.entryContentHeader){
  151. this.setContentHeader(this.entryContentHeader, entry);
  152. }
  153. if(this.entryContentNode){
  154. this.setContent(this.entryContentNode, this._editMode, entry);
  155. }
  156. }
  157. this._displaySections();
  158. },
  159. setTitleHeader: function(/*DOM node*/titleHeaderNode, /*object*/entry){
  160. // summary:
  161. // Function to set the contents of the title header node in the template to some value.
  162. // description:
  163. // Function to set the contents of the title header node in the template to some value.
  164. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  165. //
  166. // titleAchorNode:
  167. // The DOM node to attach the title data to.
  168. // editMode:
  169. // Boolean to indicate if the display should be in edit mode or not.
  170. // entry:
  171. // The Feed Entry to work with.
  172. //
  173. if(entry.title && entry.title.value && entry.title.value !== null){
  174. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  175. var titleHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.title});
  176. titleHeaderNode.appendChild(titleHeader.domNode);
  177. }
  178. },
  179. setTitle: function(titleAnchorNode, editMode, entry){
  180. // summary:
  181. // Function to set the contents of the title node in the template to some value from the entry.
  182. // description:
  183. // Function to set the contents of the title node in the template to some value from the entry.
  184. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  185. //
  186. // titleAchorNode:
  187. // The DOM node to attach the title data to.
  188. // editMode:
  189. // Boolean to indicate if the display should be in edit mode or not.
  190. // entry:
  191. // The Feed Entry to work with.
  192. if(entry.title && entry.title.value && entry.title.value !== null){
  193. if(entry.title.type == "text"){
  194. var titleNode = document.createTextNode(entry.title.value);
  195. titleAnchorNode.appendChild(titleNode);
  196. }else{
  197. var titleViewNode = document.createElement("span");
  198. var titleView = new dijit.layout.ContentPane({refreshOnShow: true, executeScripts: false}, titleViewNode);
  199. titleView.attr('content', entry.title.value);
  200. titleAnchorNode.appendChild(titleView.domNode);
  201. }
  202. this.setFieldValidity("title", true);
  203. }
  204. },
  205. setAuthorsHeader: function(/*DOM node*/authorHeaderNode, /*object*/entry){
  206. // summary:
  207. // Function to set the title format for the authors section of the author row in the template to some value from the entry.
  208. // description:
  209. // Function to set the title format for the authors section of the author row in the template to some value from the entry.
  210. // This exists specifically so users can over-ride how the author data is filled out from an entry.
  211. //
  212. // authorHeaderNode:
  213. // The DOM node to attach the author section header data to.
  214. // entry:
  215. // The Feed Entry to work with.
  216. if(entry.authors && entry.authors.length > 0){
  217. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  218. var authorHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.authors});
  219. authorHeaderNode.appendChild(authorHeader.domNode);
  220. }
  221. },
  222. setAuthors: function(/*DOM node*/authorsAnchorNode, /*boolean*/editMode, /*object*/entry){
  223. // summary:
  224. // Function to set the contents of the author node in the template to some value from the entry.
  225. // description:
  226. // Function to set the contents of the author node in the template to some value from the entry.
  227. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  228. //
  229. // authorsAchorNode:
  230. // The DOM node to attach the author data to.
  231. // editMode:
  232. // Boolean to indicate if the display should be in edit mode or not.
  233. // entry:
  234. // The Feed Entry to work with.
  235. authorsAnchorNode.innerHTML = "";
  236. if(entry.authors && entry.authors.length > 0){
  237. for(var i in entry.authors){
  238. if(entry.authors[i].name){
  239. var anchor = authorsAnchorNode;
  240. if(entry.authors[i].uri){
  241. var link = document.createElement("a");
  242. anchor.appendChild(link);
  243. link.href = entry.authors[i].uri;
  244. anchor = link;
  245. }
  246. var name = entry.authors[i].name;
  247. if(entry.authors[i].email){
  248. name = name + " (" + entry.authors[i].email + ")";
  249. }
  250. var authorNode = document.createTextNode(name);
  251. anchor.appendChild(authorNode);
  252. var breakNode = document.createElement("br");
  253. authorsAnchorNode.appendChild(breakNode);
  254. this.setFieldValidity("authors", true);
  255. }
  256. }
  257. }
  258. },
  259. setContributorsHeader: function(/*DOM node*/contributorsHeaderNode, /*object*/entry){
  260. // summary:
  261. // Function to set the contents of the contributor header node in the template to some value from the entry.
  262. // description:
  263. // Function to set the contents of the contributor header node in the template to some value from the entry.
  264. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  265. //
  266. // contributorsHeaderNode:
  267. // The DOM node to attach the contributor title to.
  268. // entry:
  269. // The Feed Entry to work with.
  270. if(entry.contributors && entry.contributors.length > 0){
  271. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  272. var contributorHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.contributors});
  273. contributorsHeaderNode.appendChild(contributorHeader.domNode);
  274. }
  275. },
  276. setContributors: function(/*DOM node*/contributorsAnchorNode, /*boolean*/editMode, /*object*/entry){
  277. // summary:
  278. // Function to set the contents of the contributor node in the template to some value from the entry.
  279. // description:
  280. // Function to set the contents of the contributor node in the template to some value from the entry.
  281. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  282. //
  283. // contributorsAnchorNode:
  284. // The DOM node to attach the contributor data to.
  285. // editMode:
  286. // Boolean to indicate if the display should be in edit mode or not.
  287. // entry:
  288. // The Feed Entry to work with.
  289. if(entry.contributors && entry.contributors.length > 0){
  290. for(var i in entry.contributors){
  291. var contributorNode = document.createTextNode(entry.contributors[i].name);
  292. contributorsAnchorNode.appendChild(contributorNode);
  293. var breakNode = document.createElement("br");
  294. contributorsAnchorNode.appendChild(breakNode);
  295. this.setFieldValidity("contributors", true);
  296. }
  297. }
  298. },
  299. setIdHeader: function(/*DOM node*/idHeaderNode, /*object*/entry){
  300. // summary:
  301. // Function to set the contents of the ID node in the template to some value from the entry.
  302. // description:
  303. // Function to set the contents of the ID node in the template to some value from the entry.
  304. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  305. //
  306. // idAnchorNode:
  307. // The DOM node to attach the ID data to.
  308. // entry:
  309. // The Feed Entry to work with.
  310. if(entry.id && entry.id !== null){
  311. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  312. var idHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.id});
  313. idHeaderNode.appendChild(idHeader.domNode);
  314. }
  315. },
  316. setId: function(/*DOM node*/idAnchorNode, /*boolean*/editMode, /*object*/entry){
  317. // summary:
  318. // Function to set the contents of the ID node in the template to some value from the entry.
  319. // description:
  320. // Function to set the contents of the ID node in the template to some value from the entry.
  321. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  322. //
  323. // idAnchorNode:
  324. // The DOM node to attach the ID data to.
  325. // editMode:
  326. // Boolean to indicate if the display should be in edit mode or not.
  327. // entry:
  328. // The Feed Entry to work with.
  329. if(entry.id && entry.id !== null){
  330. var idNode = document.createTextNode(entry.id);
  331. idAnchorNode.appendChild(idNode);
  332. this.setFieldValidity("id", true);
  333. }
  334. },
  335. setUpdatedHeader: function(/*DOM node*/updatedHeaderNode, /*object*/entry){
  336. // summary:
  337. // Function to set the contents of the updated header node in the template to some value from the entry.
  338. // description:
  339. // Function to set the contents of the updated header node in the template to some value from the entry.
  340. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  341. //
  342. // updatedHeaderNode:
  343. // The DOM node to attach the updated header data to.
  344. // entry:
  345. // The Feed Entry to work with.
  346. if(entry.updated && entry.updated !== null){
  347. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  348. var updatedHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.updated});
  349. updatedHeaderNode.appendChild(updatedHeader.domNode);
  350. }
  351. },
  352. setUpdated: function(/*DOM node*/updatedAnchorNode, /*boolean*/editMode, /*object*/entry){
  353. // summary:
  354. // Function to set the contents of the updated node in the template to some value from the entry.
  355. // description:
  356. // Function to set the contents of the updated node in the template to some value from the entry.
  357. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  358. //
  359. // updatedAnchorNode:
  360. // The DOM node to attach the udpated data to.
  361. // editMode:
  362. // Boolean to indicate if the display should be in edit mode or not.
  363. // entry:
  364. // The Feed Entry to work with.
  365. if(entry.updated && entry.updated !== null){
  366. var updatedNode = document.createTextNode(entry.updated);
  367. updatedAnchorNode.appendChild(updatedNode);
  368. this.setFieldValidity("updated", true);
  369. }
  370. },
  371. setSummaryHeader: function(/*DOM node*/summaryHeaderNode, /*object*/entry){
  372. // summary:
  373. // Function to set the contents of the summary node in the template to some value from the entry.
  374. // description:
  375. // Function to set the contents of the summary node in the template to some value from the entry.
  376. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  377. //
  378. // summaryHeaderNode:
  379. // The DOM node to attach the summary title to.
  380. // entry:
  381. // The Feed Entry to work with.
  382. if(entry.summary && entry.summary.value && entry.summary.value !== null){
  383. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  384. var summaryHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.summary});
  385. summaryHeaderNode.appendChild(summaryHeader.domNode);
  386. }
  387. },
  388. setSummary: function(/*DOM node*/summaryAnchorNode, /*boolean*/editMode, /*object*/entry){
  389. // summary:
  390. // Function to set the contents of the summary node in the template to some value from the entry.
  391. // description:
  392. // Function to set the contents of the summary node in the template to some value from the entry.
  393. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  394. //
  395. // summaryAnchorNode:
  396. // The DOM node to attach the summary data to.
  397. // editMode:
  398. // Boolean to indicate if the display should be in edit mode or not.
  399. // entry:
  400. // The Feed Entry to work with.
  401. if(entry.summary && entry.summary.value && entry.summary.value !== null){
  402. var summaryViewNode = document.createElement("span");
  403. var summaryView = new dijit.layout.ContentPane({refreshOnShow: true, executeScripts: false}, summaryViewNode);
  404. summaryView.attr('content', entry.summary.value);
  405. summaryAnchorNode.appendChild(summaryView.domNode);
  406. this.setFieldValidity("summary", true);
  407. }
  408. },
  409. setContentHeader: function(/*DOM node*/contentHeaderNode, /*object*/entry){
  410. // summary:
  411. // Function to set the contents of the content node in the template to some value from the entry.
  412. // description:
  413. // Function to set the contents of the content node in the template to some value from the entry.
  414. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  415. //
  416. // contentHeaderNode:
  417. // The DOM node to attach the content data to.
  418. // entry:
  419. // The Feed Entry to work with.
  420. if(entry.content && entry.content.value && entry.content.value !== null){
  421. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  422. var contentHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.content});
  423. contentHeaderNode.appendChild(contentHeader.domNode);
  424. }
  425. },
  426. setContent: function(/*DOM node*/contentAnchorNode, /*boolean*/editMode, /*object*/entry){
  427. // summary:
  428. // Function to set the contents of the content node in the template to some value from the entry.
  429. // description:
  430. // Function to set the contents of the content node in the template to some value from the entry.
  431. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  432. //
  433. // contentAnchorNode:
  434. // The DOM node to attach the content data to.
  435. // editMode:
  436. // Boolean to indicate if the display should be in edit mode or not.
  437. // entry:
  438. // The Feed Entry to work with.
  439. if(entry.content && entry.content.value && entry.content.value !== null){
  440. var contentViewNode = document.createElement("span");
  441. var contentView = new dijit.layout.ContentPane({refreshOnShow: true, executeScripts: false},contentViewNode);
  442. contentView.attr('content', entry.content.value);
  443. contentAnchorNode.appendChild(contentView.domNode);
  444. this.setFieldValidity("content", true);
  445. }
  446. },
  447. _displaySections: function(){
  448. // summary:
  449. // Internal function for determining which sections of the view to actually display.
  450. // description:
  451. // Internal function for determining which sections of the view to actually display.
  452. //
  453. // returns:
  454. // Nothing.
  455. dojo.style(this.entryTitleRow, 'display', 'none');
  456. dojo.style(this.entryAuthorRow, 'display', 'none');
  457. dojo.style(this.entryContributorRow, 'display', 'none');
  458. dojo.style(this.entrySummaryRow, 'display', 'none');
  459. dojo.style(this.entryContentRow, 'display', 'none');
  460. dojo.style(this.entryIdRow, 'display', 'none');
  461. dojo.style(this.entryUpdatedRow, 'display', 'none');
  462. for(var i in this._displayEntrySections){
  463. var section = this._displayEntrySections[i].toLowerCase();
  464. if(section === "title" && this.isFieldValid("title")){
  465. dojo.style(this.entryTitleRow, 'display', '');
  466. }
  467. if(section === "authors" && this.isFieldValid("authors")){
  468. dojo.style(this.entryAuthorRow, 'display', '');
  469. }
  470. if(section === "contributors" && this.isFieldValid("contributors")){
  471. dojo.style(this.entryContributorRow, 'display', '');
  472. }
  473. if(section === "summary" && this.isFieldValid("summary")){
  474. dojo.style(this.entrySummaryRow, 'display', '');
  475. }
  476. if(section === "content" && this.isFieldValid("content")){
  477. dojo.style(this.entryContentRow, 'display', '');
  478. }
  479. if(section === "id" && this.isFieldValid("id")){
  480. dojo.style(this.entryIdRow, 'display', '');
  481. }
  482. if(section === "updated" && this.isFieldValid("updated")){
  483. dojo.style(this.entryUpdatedRow, 'display', '');
  484. }
  485. }
  486. },
  487. setDisplaySections: function(/*array*/sectionsArray){
  488. // summary:
  489. // Function for setting which sections of the entry should be displayed.
  490. // description:
  491. // Function for setting which sections of the entry should be displayed.
  492. //
  493. // sectionsArray:
  494. // Array of string names that indicate which sections to display.
  495. //
  496. // returns:
  497. // Nothing.
  498. if(sectionsArray !== null){
  499. this._displayEntrySections = sectionsArray;
  500. this._displaySections();
  501. }else{
  502. this._displayEntrySections = ["title","authors","contributors","summary","content","id","updated"];
  503. }
  504. },
  505. _setDisplaySectionsCheckboxes: function(){
  506. // summary:
  507. // Internal function for setting which checkboxes on the display are selected.
  508. // description:
  509. // Internal function for setting which checkboxes on the display are selected.
  510. //
  511. // returns:
  512. // Nothing.
  513. var items = ["title","authors","contributors","summary","content","id","updated"];
  514. for(var i in items){
  515. if(dojo.indexOf(this._displayEntrySections, items[i]) == -1){
  516. dojo.style(this["feedEntryCell"+items[i]], 'display', 'none');
  517. }else{
  518. this["feedEntryCheckBox"+items[i].substring(0,1).toUpperCase()+items[i].substring(1)].checked=true;
  519. }
  520. }
  521. },
  522. _readDisplaySections: function(){
  523. // summary:
  524. // Internal function for reading what is currently checked for display and generating the display list from it.
  525. // description:
  526. // Internal function for reading what is currently checked for display and generating the display list from it.
  527. //
  528. // returns:
  529. // Nothing.
  530. var checkedList = [];
  531. if(this.feedEntryCheckBoxTitle.checked){
  532. checkedList.push("title");
  533. }
  534. if(this.feedEntryCheckBoxAuthors.checked){
  535. checkedList.push("authors");
  536. }
  537. if(this.feedEntryCheckBoxContributors.checked){
  538. checkedList.push("contributors");
  539. }
  540. if(this.feedEntryCheckBoxSummary.checked){
  541. checkedList.push("summary");
  542. }
  543. if(this.feedEntryCheckBoxContent.checked){
  544. checkedList.push("content");
  545. }
  546. if(this.feedEntryCheckBoxId.checked){
  547. checkedList.push("id");
  548. }
  549. if(this.feedEntryCheckBoxUpdated.checked){
  550. checkedList.push("updated");
  551. }
  552. this._displayEntrySections = checkedList;
  553. },
  554. _toggleCheckbox: function(/*object*/checkBox){
  555. // summary:
  556. // Internal function for determining of a particular entry is editable.
  557. // description:
  558. // Internal function for determining of a particular entry is editable.
  559. // This is used for determining if the delete action should be displayed or not.
  560. //
  561. // checkBox:
  562. // The checkbox object to toggle the selection on.
  563. //
  564. // returns:
  565. // Nothing
  566. if(checkBox.checked){
  567. checkBox.checked=false;
  568. }else{
  569. checkBox.checked=true;
  570. }
  571. this._readDisplaySections();
  572. this._displaySections();
  573. },
  574. _toggleOptions: function(/*object*/checkBox){
  575. // summary:
  576. // Internal function for determining of a particular entry is editable.
  577. // description:
  578. // Internal function for determining of a particular entry is editable.
  579. // This is used for determining if the delete action should be displayed or not.
  580. //
  581. // checkBox:
  582. // The checkbox object to toggle the selection on.
  583. //
  584. // returns:
  585. // Nothing
  586. if(this.enableMenu){
  587. var fade = null;
  588. var anim;
  589. var anim2;
  590. if(this._optionButtonDisplayed){
  591. if(this.enableMenuFade){
  592. anim = dojo.fadeOut({node: this.entryCheckBoxDisplayOptions,duration: 250});
  593. dojo.connect(anim, "onEnd", this, function(){
  594. dojo.style(this.entryCheckBoxDisplayOptions, 'display', 'none');
  595. dojo.style(this.entryCheckBoxRow, 'display', '');
  596. dojo.style(this.entryCheckBoxRow2, 'display', '');
  597. dojo.fadeIn({node: this.entryCheckBoxRow, duration: 250}).play();
  598. dojo.fadeIn({node: this.entryCheckBoxRow2, duration: 250}).play();
  599. });
  600. anim.play();
  601. }else{
  602. dojo.style(this.entryCheckBoxDisplayOptions, 'display', 'none');
  603. dojo.style(this.entryCheckBoxRow, 'display', '');
  604. dojo.style(this.entryCheckBoxRow2, 'display', '');
  605. }
  606. this._optionButtonDisplayed=false;
  607. }else{
  608. if(this.enableMenuFade){
  609. anim = dojo.fadeOut({node: this.entryCheckBoxRow,duration: 250});
  610. anim2 = dojo.fadeOut({node: this.entryCheckBoxRow2,duration: 250});
  611. dojo.connect(anim, "onEnd", this, function(){
  612. dojo.style(this.entryCheckBoxRow, 'display', 'none');
  613. dojo.style(this.entryCheckBoxRow2, 'display', 'none');
  614. dojo.style(this.entryCheckBoxDisplayOptions, 'display', '');
  615. dojo.fadeIn({node: this.entryCheckBoxDisplayOptions, duration: 250}).play();
  616. });
  617. anim.play();
  618. anim2.play();
  619. }else{
  620. dojo.style(this.entryCheckBoxRow, 'display', 'none');
  621. dojo.style(this.entryCheckBoxRow2, 'display', 'none');
  622. dojo.style(this.entryCheckBoxDisplayOptions, 'display', '');
  623. }
  624. this._optionButtonDisplayed=true;
  625. }
  626. }
  627. },
  628. _handleEvent: function(/*object*/entrySelectionEvent){
  629. // summary:
  630. // Internal function for listening to a topic that will handle entry notification.
  631. // description:
  632. // Internal function for listening to a topic that will handle entry notification.
  633. //
  634. // entrySelectionEvent:
  635. // The topic message containing the entry that was selected for view.
  636. //
  637. // returns:
  638. // Nothing.
  639. if(entrySelectionEvent.source != this){
  640. if(entrySelectionEvent.action == "set" && entrySelectionEvent.entry){
  641. this.setEntry(entrySelectionEvent.entry, entrySelectionEvent.feed);
  642. }else if(entrySelectionEvent.action == "delete" && entrySelectionEvent.entry && entrySelectionEvent.entry == this._entry){
  643. this.clear();
  644. }
  645. }
  646. },
  647. setFieldValidity: function(/*string*/field, /*boolean*/isValid){
  648. // summary:
  649. // Function to set whether a field in the view is valid and displayable.
  650. // description:
  651. // Function to set whether a field in the view is valid and displayable.
  652. // This is needed for over-riding of the set* functions and customization of how data is displayed in the attach point.
  653. // So if custom implementations use their own display logic, they can still enable the field.
  654. //
  655. // field:
  656. // The field name to set the valid parameter on. Such as 'content', 'id', etc.
  657. // isValid:
  658. // Flag denoting if the field is valid or not.
  659. //
  660. // returns:
  661. // Nothing.
  662. if(field){
  663. var lowerField = field.toLowerCase();
  664. this._validEntryFields[field] = isValid;
  665. }
  666. },
  667. isFieldValid: function(/*string*/field){
  668. // summary:
  669. // Function to return if a displayable field is valid or not
  670. // description:
  671. // Function to return if a displayable field is valid or not
  672. //
  673. // field:
  674. // The field name to get the valid parameter of. Such as 'content', 'id', etc.
  675. //
  676. // returns:
  677. // boolean denoting if the field is valid and set.
  678. return this._validEntryFields[field.toLowerCase()];
  679. },
  680. getEntry: function(){
  681. return this._entry;
  682. },
  683. getFeed: function(){
  684. return this._feed;
  685. },
  686. destroy: function(){
  687. this.clear();
  688. dojo.forEach(this._subscriptions, dojo.unsubscribe);
  689. }
  690. });
  691. dojo.declare("dojox.atom.widget.EntryHeader",[dijit._Widget, dijit._Templated, dijit._Container],{
  692. // summary:
  693. // Widget representing a header in a FeedEntryViewer/Editor
  694. // description:
  695. // Widget representing a header in a FeedEntryViewer/Editor
  696. title: "",
  697. templateString: dojo.cache("dojox.atom", "widget/templates/EntryHeader.html", "<span dojoAttachPoint=\"entryHeaderNode\" class=\"entryHeaderNode\"></span>\n"),
  698. postCreate: function(){
  699. this.setListHeader();
  700. },
  701. setListHeader: function(/*string*/title){
  702. this.clear();
  703. if(title){
  704. this.title = title;
  705. }
  706. var textNode = document.createTextNode(this.title);
  707. this.entryHeaderNode.appendChild(textNode);
  708. },
  709. clear: function(){
  710. this.destroyDescendants();
  711. if(this.entryHeaderNode){
  712. for(var i = 0; i < this.entryHeaderNode.childNodes.length; i++){
  713. this.entryHeaderNode.removeChild(this.entryHeaderNode.childNodes[i]);
  714. }
  715. }
  716. },
  717. destroy: function(){
  718. this.clear();
  719. }
  720. });
  721. }