FeedEntryEditor.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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.FeedEntryEditor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.atom.widget.FeedEntryEditor"] = true;
  8. dojo.provide("dojox.atom.widget.FeedEntryEditor");
  9. dojo.require("dojox.atom.widget.FeedEntryViewer");
  10. dojo.require("dijit._Widget");
  11. dojo.require("dijit._Templated");
  12. dojo.require("dijit._Container");
  13. dojo.require("dijit.Editor");
  14. dojo.require("dijit.form.TextBox");
  15. dojo.require("dijit.form.SimpleTextarea");
  16. dojo.requireLocalization("dojox.atom.widget", "FeedEntryEditor", 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");
  17. dojo.requireLocalization("dojox.atom.widget", "PeopleEditor", 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");
  18. dojo.experimental("dojox.atom.widget.FeedEntryEditor");
  19. dojo.declare("dojox.atom.widget.FeedEntryEditor",dojox.atom.widget.FeedEntryViewer,{
  20. // summary:
  21. // An ATOM feed entry editor that allows viewing of the individual attributes of an entry.
  22. // description:
  23. // An ATOM feed entry editor that allows viewing of the individual attributes of an entry.
  24. _contentEditor: null,
  25. _oldContent: null,
  26. _setObject: null,
  27. enableEdit: false,
  28. _contentEditorCreator: null,
  29. _editors: {},
  30. entryNewButton: null,
  31. _editable: false, //Flag denoting if the current entry is editable or not.
  32. //Templates for the HTML rendering. Need to figure these out better, admittedly.
  33. templateString: dojo.cache("dojox.atom", "widget/templates/FeedEntryEditor.html", "<div class=\"feedEntryViewer\">\n <table border=\"0\" width=\"100%\" class=\"feedEntryViewerMenuTable\" dojoAttachPoint=\"feedEntryViewerMenu\" style=\"display: none;\">\n <tr width=\"100%\" dojoAttachPoint=\"entryCheckBoxDisplayOptions\">\n \t<td align=\"left\" dojoAttachPoint=\"entryNewButton\">\n <span class=\"feedEntryViewerMenu\" dojoAttachPoint=\"doNew\" dojoAttachEvent=\"onclick:_toggleNew\"></span>\n \t</td>\n <td align=\"left\" dojoAttachPoint=\"entryEditButton\" style=\"display: none;\">\n <span class=\"feedEntryViewerMenu\" dojoAttachPoint=\"edit\" dojoAttachEvent=\"onclick:_toggleEdit\"></span>\n </td>\n <td align=\"left\" dojoAttachPoint=\"entrySaveCancelButtons\" style=\"display: none;\">\n <span class=\"feedEntryViewerMenu\" dojoAttachPoint=\"save\" dojoAttachEvent=\"onclick:saveEdits\"></span>\n <span class=\"feedEntryViewerMenu\" dojoAttachPoint=\"cancel\" dojoAttachEvent=\"onclick:cancelEdits\"></span>\n </td>\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>\n \t<select dojoAttachPoint=\"entryTitleSelect\" dojoAttachEvent=\"onchange:_switchEditor\" style=\"display: none\">\n \t\t<option value=\"text\">Text</option>\n\t\t\t\t\t\t\t\t<option value=\"html\">HTML</option>\n\t\t\t\t\t\t\t\t<option value=\"xhtml\">XHTML</option>\n \t</select>\n </td>\n </tr>\n <tr>\n <td colspan=\"2\" 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\" colspan=\"2\">\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>\n \t<select dojoAttachPoint=\"entrySummarySelect\" dojoAttachEvent=\"onchange:_switchEditor\" style=\"display: none\">\n \t\t<option value=\"text\">Text</option>\n\t\t\t\t\t\t\t\t<option value=\"html\">HTML</option>\n\t\t\t\t\t\t\t\t<option value=\"xhtml\">XHTML</option>\n \t</select>\n </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>\n \t<select dojoAttachPoint=\"entryContentSelect\" dojoAttachEvent=\"onchange:_switchEditor\" style=\"display: none\">\n \t\t<option value=\"text\">Text</option>\n\t\t\t\t\t\t\t\t<option value=\"html\">HTML</option>\n\t\t\t\t\t\t\t\t<option value=\"xhtml\">XHTML</option>\n \t</select>\n </td>\n </tr>\n <tr>\n <td dojoAttachPoint=\"entryContentNode\">\n </td>\n </tr>\n </table>\n </td>\n </tr>\n </table>\n</div>\n"),
  34. postCreate: function(){
  35. if(this.entrySelectionTopic !== ""){
  36. this._subscriptions = [dojo.subscribe(this.entrySelectionTopic, this, "_handleEvent")];
  37. }
  38. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  39. this.displayOptions.innerHTML = _nlsResources.displayOptions;
  40. this.feedEntryCheckBoxLabelTitle.innerHTML = _nlsResources.title;
  41. this.feedEntryCheckBoxLabelAuthors.innerHTML = _nlsResources.authors;
  42. this.feedEntryCheckBoxLabelContributors.innerHTML = _nlsResources.contributors;
  43. this.feedEntryCheckBoxLabelId.innerHTML = _nlsResources.id;
  44. this.close.innerHTML = _nlsResources.close;
  45. this.feedEntryCheckBoxLabelUpdated.innerHTML = _nlsResources.updated;
  46. this.feedEntryCheckBoxLabelSummary.innerHTML = _nlsResources.summary;
  47. this.feedEntryCheckBoxLabelContent.innerHTML = _nlsResources.content;
  48. _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryEditor");
  49. this.doNew.innerHTML = _nlsResources.doNew;
  50. this.edit.innerHTML = _nlsResources.edit;
  51. this.save.innerHTML = _nlsResources.save;
  52. this.cancel.innerHTML = _nlsResources.cancel;
  53. },
  54. setEntry: function(/*object*/entry, /*object*/feed, /*boolean*/leaveMenuState){
  55. // summary:
  56. // Function to set the current entry that is being edited.
  57. // description:
  58. // Function to set the current entry that is being edited.
  59. //
  60. // entry:
  61. // Instance of dojox.atom.io.model.Entry to display for reading/editing.
  62. if(this._entry !== entry){
  63. //If we swap entries, we don't want to keep the menu states and modes.
  64. this._editMode=false;
  65. leaveMenuState=false;
  66. }else{
  67. leaveMenuState = true;
  68. }
  69. dojox.atom.widget.FeedEntryEditor.superclass.setEntry.call(this, entry, feed);
  70. this._editable = this._isEditable(entry);
  71. if(!leaveMenuState && !this._editable){
  72. dojo.style(this.entryEditButton, 'display', 'none');
  73. dojo.style(this.entrySaveCancelButtons, 'display', 'none');
  74. }
  75. if(this._editable && this.enableEdit){
  76. if(!leaveMenuState){
  77. dojo.style(this.entryEditButton, 'display', '');
  78. //TODO double check this &&...
  79. if(this.enableMenuFade && this.entrySaveCancelButton){
  80. dojo.fadeOut({node: this.entrySaveCancelButton,duration: 250}).play();
  81. }
  82. }
  83. }
  84. },
  85. _toggleEdit: function(){
  86. // summary:
  87. // Internal function for toggling/enabling the display of edit mode
  88. // description:
  89. // Internal function for toggling/enabling the display of edit mode
  90. //
  91. // returns:
  92. // Nothing.
  93. if(this._editable && this.enableEdit){
  94. dojo.style(this.entryEditButton, 'display', 'none');
  95. dojo.style(this.entrySaveCancelButtons, 'display', '');
  96. this._editMode = true;
  97. //Rebuild the view using the same entry and feed.
  98. this.setEntry(this._entry, this._feed, true);
  99. }
  100. },
  101. _handleEvent: function(/*object*/entrySelectionEvent){
  102. // summary:
  103. // Internal function for listening to a topic that will handle entry notification.
  104. // description:
  105. // Internal function for listening to a topic that will handle entry notification.
  106. //
  107. // entrySelectionEvent:
  108. // The topic message containing the entry that was selected for view.
  109. //
  110. // returns:
  111. // Nothing.
  112. if(entrySelectionEvent.source != this && entrySelectionEvent.action == "delete" &&
  113. entrySelectionEvent.entry && entrySelectionEvent.entry == this._entry){
  114. dojo.style(this.entryEditButton, 'display', 'none');
  115. }
  116. dojox.atom.widget.FeedEntryEditor.superclass._handleEvent.call(this, entrySelectionEvent);
  117. },
  118. _isEditable: function(/*object*/entry){
  119. // summary:
  120. // Internal function for determining of a particular entry is editable.
  121. // description:
  122. // Internal function for determining of a particular entry is editable.
  123. // This is used for determining if the delete action should be displayed or not.
  124. //
  125. // entry:
  126. // The dojox.atom.io.model.Entry object to examine
  127. //
  128. // returns:
  129. // Boolean denoting if the entry seems editable or not..
  130. var retVal = false;
  131. if(entry && entry !== null && entry.links && entry.links !== null){
  132. for(var x in entry.links){
  133. if(entry.links[x].rel && entry.links[x].rel == "edit"){
  134. retVal = true;
  135. break;
  136. }
  137. }
  138. }
  139. return retVal;
  140. },
  141. // The following set<Attribute> functions override the corresponding functions in FeedEntryViewer. These handle
  142. // the editMode flag by inserting appropriate editor widgets inside of just splashing the content in the page.
  143. setTitle: function(/*DOM node*/titleAnchorNode, /*boolean*/editMode, /*object*/entry){
  144. // summary:
  145. // Function to set the contents of the title node in the template to some value from the entry.
  146. // description:
  147. // Function to set the contents of the title node in the template to some value from the entry.
  148. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  149. //
  150. // titleAnchorNode:
  151. // The DOM node to attach the title data to.
  152. // editMode:
  153. // Boolean to indicate if the display should be in edit mode or not.
  154. // entry:
  155. // The Feed Entry to work with.
  156. //
  157. if(!editMode){
  158. dojox.atom.widget.FeedEntryEditor.superclass.setTitle.call(this, titleAnchorNode, editMode, entry);
  159. if(entry.title && entry.title.value && entry.title.value !== null){
  160. this.setFieldValidity("title", true);
  161. }
  162. }else{
  163. if(entry.title && entry.title.value && entry.title.value !== null){
  164. if(!this._toLoad){
  165. this._toLoad = [];
  166. }
  167. this.entryTitleSelect.value = entry.title.type;
  168. var editor = this._createEditor(titleAnchorNode, entry.title, true, entry.title.type === "html" || entry.title.type === "xhtml");
  169. editor.name = "title";
  170. this._toLoad.push(editor);
  171. this.setFieldValidity("titleedit",true);
  172. this.setFieldValidity("title",true);
  173. }
  174. }
  175. },
  176. setAuthors: function(/*DOM node*/authorsAnchorNode, /*boolean*/editMode, /*object*/entry){
  177. // summary:
  178. // Function to set the contents of the author node in the template to some value from the entry.
  179. // description:
  180. // Function to set the contents of the author node in the template to some value from the entry.
  181. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  182. //
  183. // authorsAnchorNode:
  184. // The DOM node to attach the author data to.
  185. // editMode:
  186. // Boolean to indicate if the display should be in edit mode or not.
  187. // entry:
  188. // The Feed Entry to work with.
  189. if(!editMode){
  190. dojox.atom.widget.FeedEntryEditor.superclass.setAuthors.call(this, authorsAnchorNode, editMode, entry);
  191. if(entry.authors && entry.authors.length > 0){
  192. this.setFieldValidity("authors", true);
  193. }
  194. }else{
  195. if(entry.authors && entry.authors.length > 0){
  196. this._editors.authors = this._createPeopleEditor(this.entryAuthorNode, {data: entry.authors, name: "Author"});
  197. this.setFieldValidity("authors", true);
  198. }
  199. }
  200. },
  201. setContributors: function(/*DOM node*/contributorsAnchorNode, /*boolean*/editMode, /*object*/entry){
  202. // summary:
  203. // Function to set the contents of the contributor node in the template to some value from the entry.
  204. // description:
  205. // Function to set the contents of the contributor node in the template to some value from the entry.
  206. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  207. //
  208. // contributorsAnchorNode:
  209. // The DOM node to attach the contributor data to.
  210. // editMode:
  211. // Boolean to indicate if the display should be in edit mode or not.
  212. // entry:
  213. // The Feed Entry to work with.
  214. if(!editMode){
  215. dojox.atom.widget.FeedEntryEditor.superclass.setContributors.call(this, contributorsAnchorNode, editMode, entry);
  216. if(entry.contributors && entry.contributors.length > 0){
  217. this.setFieldValidity("contributors", true);
  218. }
  219. }else{
  220. if(entry.contributors && entry.contributors.length > 0){
  221. this._editors.contributors = this._createPeopleEditor(this.entryContributorNode, {data: entry.contributors, name: "Contributor"});
  222. this.setFieldValidity("contributors", true);
  223. }
  224. }
  225. },
  226. setId: function(/*DOM node*/idAnchorNode, /*boolean*/editMode, /*object*/entry){
  227. // summary:
  228. // Function to set the contents of the ID node in the template to some value from the entry.
  229. // description:
  230. // Function to set the contents of the ID node in the template to some value from the entry.
  231. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  232. //
  233. // idAnchorNode:
  234. // The DOM node to attach the ID data to.
  235. // editMode:
  236. // Boolean to indicate if the display should be in edit mode or not.
  237. // entry:
  238. // The Feed Entry to work with.
  239. if(!editMode){
  240. dojox.atom.widget.FeedEntryEditor.superclass.setId.call(this, idAnchorNode, editMode, entry);
  241. if(entry.id && entry.id !== null){
  242. this.setFieldValidity("id", true);
  243. }
  244. }else{
  245. if(entry.id && entry.id !== null){
  246. this._editors.id = this._createEditor(idAnchorNode, entry.id);
  247. this.setFieldValidity("id",true);
  248. }
  249. }
  250. },
  251. setUpdated: function(/*DOM node*/updatedAnchorNode, /*boolean*/editMode, /*object*/entry){
  252. // summary:
  253. // Function to set the contents of the updated node in the template to some value from the entry.
  254. // description:
  255. // Function to set the contents of the updated node in the template to some value from the entry.
  256. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  257. //
  258. // updatedAnchorNode:
  259. // The DOM node to attach the udpated data to.
  260. // editMode:
  261. // Boolean to indicate if the display should be in edit mode or not.
  262. // entry:
  263. // The Feed Entry to work with.
  264. if(!editMode){
  265. dojox.atom.widget.FeedEntryEditor.superclass.setUpdated.call(this, updatedAnchorNode, editMode, entry);
  266. if(entry.updated && entry.updated !== null){
  267. this.setFieldValidity("updated", true);
  268. }
  269. }else{
  270. if(entry.updated && entry.updated !== null){
  271. this._editors.updated = this._createEditor(updatedAnchorNode, entry.updated);
  272. this.setFieldValidity("updated",true);
  273. }
  274. }
  275. },
  276. setSummary: function(/*DOM node*/summaryAnchorNode, /*boolean*/editMode, /*object*/entry){
  277. // summary:
  278. // Function to set the contents of the summary node in the template to some value from the entry.
  279. // description:
  280. // Function to set the contents of the summary 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. // summaryAnchorNode:
  284. // The DOM node to attach the summary 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(!editMode){
  290. dojox.atom.widget.FeedEntryEditor.superclass.setSummary.call(this, summaryAnchorNode, editMode, entry);
  291. if(entry.summary && entry.summary.value && entry.summary.value !== null){
  292. this.setFieldValidity("summary", true);
  293. }
  294. }else{
  295. if(entry.summary && entry.summary.value && entry.summary.value !== null){
  296. if(!this._toLoad){
  297. this._toLoad = [];
  298. }
  299. this.entrySummarySelect.value = entry.summary.type;
  300. var editor = this._createEditor(summaryAnchorNode, entry.summary, true, entry.summary.type === "html" || entry.summary.type === "xhtml");
  301. editor.name = "summary";
  302. this._toLoad.push(editor);
  303. this.setFieldValidity("summaryedit",true);
  304. this.setFieldValidity("summary",true);
  305. }
  306. }
  307. },
  308. setContent: function(/*DOM node*/contentAnchorNode, /*boolean*/editMode, /*object*/entry){
  309. // summary:
  310. // Function to set the contents of the content node in the template to some value from the entry.
  311. // description:
  312. // Function to set the contents of the content node in the template to some value from the entry.
  313. // This exists specifically so users can over-ride how the title data is filled out from an entry.
  314. //
  315. // summaryAnchorNode:
  316. // The DOM node to attach the content data to.
  317. // editMode:
  318. // Boolean to indicate if the display should be in edit mode or not.
  319. // entry:
  320. // The Feed Entry to work with.
  321. if(!editMode){
  322. dojox.atom.widget.FeedEntryEditor.superclass.setContent.call(this, contentAnchorNode, editMode, entry);
  323. if(entry.content && entry.content.value && entry.content.value !== null){
  324. this.setFieldValidity("content",true);
  325. }
  326. }else{
  327. if(entry.content && entry.content.value && entry.content.value !== null){
  328. if(!this._toLoad){
  329. this._toLoad = [];
  330. }
  331. this.entryContentSelect.value = entry.content.type;
  332. var editor = this._createEditor(contentAnchorNode, entry.content, true, entry.content.type === "html" || entry.content.type === "xhtml");
  333. editor.name = "content";
  334. this._toLoad.push(editor);
  335. this.setFieldValidity("contentedit",true);
  336. this.setFieldValidity("content",true);
  337. }
  338. }
  339. },
  340. _createEditor: function(/*DOM node*/anchorNode, /*DOM node*/node, /*boolean*/multiline, /*object*/rte){
  341. // summary:
  342. // Function to create an appropriate text editor widget based on the given parameters.
  343. // description:
  344. // Function to create an appropriate text editor widget based on the given parameters.
  345. //
  346. // anchorNode:
  347. // The DOM node to attach the editor widget to.
  348. // node:
  349. // An object containing the value to be put into the editor. This ranges from an anonymous object
  350. // with a value parameter to a dojox.atom.io.model.Content object.
  351. // multiline:
  352. // A boolean indicating whether the content should be multiline (such as a textarea) instead of a
  353. // single line (such as a textbox).
  354. // rte:
  355. // A boolean indicating whether the content should be a rich text editor widget.
  356. //
  357. // returns:
  358. // Either a widget (for textarea or textbox widgets) or an anonymous object to be used to create a
  359. // rich text area widget.
  360. var viewNode;
  361. var box;
  362. if(!node){
  363. if(rte){
  364. // Returns an anonymous object which would then be loaded later, after the containing element
  365. // exists on the page.
  366. return {anchorNode: anchorNode,
  367. entryValue: "",
  368. editor: null,
  369. generateEditor: function(){
  370. // The only way I found I could get the editor to behave consistently was to
  371. // create the content on a span, and allow the content editor to replace it.
  372. // This gets around the dynamic/delayed way in which content editors get created.
  373. var node = document.createElement("div");
  374. node.innerHTML = this.entryValue;
  375. this.anchorNode.appendChild(node);
  376. var _editor = new dijit.Editor({}, node);
  377. this.editor = _editor;
  378. return _editor;
  379. }
  380. };
  381. }
  382. if(multiline){
  383. // If multiline, create a textarea
  384. viewNode = document.createElement("textarea");
  385. anchorNode.appendChild(viewNode);
  386. dojo.style(viewNode, 'width', '90%');
  387. box = new dijit.form.SimpleTextarea({},viewNode);
  388. }else{
  389. // If single line, create a textbox.
  390. viewNode = document.createElement("input");
  391. anchorNode.appendChild(viewNode);
  392. dojo.style(viewNode, 'width', '95%');
  393. box = new dijit.form.TextBox({},viewNode);
  394. }
  395. box.attr('value', '');
  396. return box;
  397. }
  398. // Check through the node parameter to get the value to be used.
  399. var value;
  400. if(node.value !== undefined){
  401. value = node.value;
  402. }else if(node.attr){
  403. value = node.attr('value');
  404. }else{
  405. value = node;
  406. }
  407. if(rte){
  408. // Returns an anonymous object which would then be loaded later, after the containing element
  409. // exists on the page.
  410. if(value.indexOf("<") != -1){
  411. value = value.replace(/</g, "&lt;");
  412. }
  413. return {anchorNode: anchorNode,
  414. entryValue: value,
  415. editor: null,
  416. generateEditor: function(){
  417. // The only way I found I could get the editor to behave consistently was to
  418. // create the content on a span, and allow the content editor to replace it.
  419. // This gets around the dynamic/delayed way in which content editors get created.
  420. var node = document.createElement("div");
  421. node.innerHTML = this.entryValue;
  422. this.anchorNode.appendChild(node);
  423. var _editor = new dijit.Editor({}, node);
  424. this.editor = _editor;
  425. return _editor;
  426. }
  427. };
  428. }
  429. if(multiline){
  430. // If multiline, create a textarea
  431. viewNode = document.createElement("textarea");
  432. anchorNode.appendChild(viewNode);
  433. dojo.style(viewNode, 'width', '90%');
  434. box = new dijit.form.SimpleTextarea({},viewNode);
  435. }else{
  436. // If single line, create a textbox.
  437. viewNode = document.createElement("input");
  438. anchorNode.appendChild(viewNode);
  439. dojo.style(viewNode, 'width', '95%');
  440. box = new dijit.form.TextBox({},viewNode);
  441. }
  442. box.attr('value', value);
  443. return box;
  444. },
  445. _switchEditor: function(/*object*/event){
  446. // summary:
  447. // Function to switch between editor types.
  448. // description:
  449. // Function to switch between a rich text editor and a textarea widget. Used for title, summary,
  450. // And content when switching between text and html/xhtml content.
  451. //
  452. // event:
  453. // The event generated by the change in the select box on the page.
  454. var type = null;
  455. var target = null;
  456. var parent = null;
  457. // Determine the source/target of this event (to determine which editor we're switching)
  458. if(dojo.isIE){
  459. target = event.srcElement;
  460. }else{
  461. target = event.target;
  462. }
  463. // Determine which editor (title, summary, or content)
  464. if(target === this.entryTitleSelect){
  465. parent = this.entryTitleNode;
  466. type = "title";
  467. } else if(target === this.entrySummarySelect){
  468. parent = this.entrySummaryNode;
  469. type = "summary";
  470. }else{
  471. parent = this.entryContentNode;
  472. type = "content";
  473. }
  474. // Grab the existing editor.
  475. var editor = this._editors[type];
  476. var newEditor;
  477. var value;
  478. if(target.value === "text"){
  479. if(editor.declaredClass === "dijit.Editor"){
  480. // If we're changing the type to text and our existing editor is a rich text editor, we need to destroy
  481. // it and switch to a multiline editor.
  482. value = editor.attr('value', false);
  483. editor.close(false,true);
  484. editor.destroy();
  485. while(parent.firstChild){
  486. dojo.destroy(parent.firstChild);
  487. }
  488. newEditor = this._createEditor(parent, {value: value}, true, false);
  489. this._editors[type] = newEditor;
  490. }
  491. }else{
  492. if(editor.declaredClass != "dijit.Editor"){
  493. // Otherwise, we're switching to a html or xhtml type, but we currently have a textarea widget. We need
  494. // to destroy the existing RTE and create a multiline textarea widget.
  495. value = editor.attr('value');
  496. editor.destroy();
  497. while(parent.firstChild){
  498. dojo.destroy(parent.firstChild);
  499. }
  500. newEditor = this._createEditor(parent, {value: value}, true, true);
  501. newEditor = dojo.hitch(newEditor, newEditor.generateEditor)();
  502. this._editors[type] = newEditor;
  503. }
  504. }
  505. },
  506. _createPeopleEditor: function(/*DOM node*/anchorNode, /*DOM node*/node){
  507. // summary:
  508. // Creates a People Editor widget and returns it.
  509. // description:
  510. // Creates a People Editor widget, sets its value, and returns it.
  511. //
  512. // anchorNode:
  513. // The node to attach the editor to.
  514. // node:
  515. // An object containing the value to be put into the editor. Typically, this is an
  516. // dojox.atom.io.model.Person object.
  517. //
  518. // returns: A new People Editor object.
  519. var viewNode = document.createElement("div");
  520. anchorNode.appendChild(viewNode);
  521. return new dojox.atom.widget.PeopleEditor(node,viewNode);
  522. },
  523. saveEdits: function(){
  524. // summary:
  525. // Saves edits submitted when the 'save' button is pressed.
  526. // description:
  527. // Saves edits submitted when the 'save' button is pressed. Distinguishes between new and existing
  528. // entries and saves appropriately. Fetches the values of the editors, and, if existing, compares them to
  529. // the existing values and submits the updates, otherwise creates a new entry and posts it as a new entry.
  530. //
  531. // returns:
  532. // Nothing.
  533. dojo.style(this.entrySaveCancelButtons, 'display', 'none');
  534. dojo.style(this.entryEditButton, 'display', '');
  535. dojo.style(this.entryNewButton, 'display', '');
  536. var modifiedEntry = false;
  537. var value;
  538. var i;
  539. var changed;
  540. var entry;
  541. var authors;
  542. var contributors;
  543. if(!this._new){
  544. entry = this.getEntry();
  545. if(this._editors.title && (this._editors.title.attr('value') != entry.title.value || this.entryTitleSelect.value != entry.title.type)){
  546. value = this._editors.title.attr('value');
  547. if(this.entryTitleSelect.value === "xhtml"){
  548. value = this._enforceXhtml(value);
  549. if(value.indexOf('<div xmlns="http://www.w3.org/1999/xhtml">') !== 0){
  550. value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>';
  551. }
  552. }
  553. entry.title = new dojox.atom.io.model.Content("title", value, null, this.entryTitleSelect.value);
  554. modifiedEntry = true;
  555. }
  556. if(this._editors.id.attr('value') != entry.id){
  557. entry.id = this._editors.id.attr('value');
  558. modifiedEntry = true;
  559. }
  560. if(this._editors.summary && (this._editors.summary.attr('value') != entry.summary.value || this.entrySummarySelect.value != entry.summary.type)){
  561. value = this._editors.summary.attr('value');
  562. if(this.entrySummarySelect.value === "xhtml"){
  563. value = this._enforceXhtml(value);
  564. if(value.indexOf('<div xmlns="http://www.w3.org/1999/xhtml">') !== 0){
  565. value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>';
  566. }
  567. }
  568. entry.summary = new dojox.atom.io.model.Content("summary", value, null, this.entrySummarySelect.value);
  569. modifiedEntry = true;
  570. }
  571. if(this._editors.content && (this._editors.content.attr('value') != entry.content.value || this.entryContentSelect.value != entry.content.type)){
  572. value = this._editors.content.attr('value');
  573. if(this.entryContentSelect.value === "xhtml"){
  574. value = this._enforceXhtml(value);
  575. if(value.indexOf('<div xmlns="http://www.w3.org/1999/xhtml">') !== 0){
  576. value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>';
  577. }
  578. }
  579. entry.content = new dojox.atom.io.model.Content("content", value, null, this.entryContentSelect.value);
  580. modifiedEntry = true;
  581. }
  582. if(this._editors.authors){
  583. if(modifiedEntry){
  584. entry.authors = [];
  585. authors = this._editors.authors.getValues();
  586. for(i in authors){
  587. if(authors[i].name || authors[i].email || authors[i].uri){
  588. entry.addAuthor(authors[i].name, authors[i].email, authors[i].uri);
  589. }
  590. }
  591. }else{
  592. var currentAuthors = entry.authors;
  593. var searchAuthors = function(name, email, uri){
  594. for(i in currentAuthors){
  595. if(currentAuthors[i].name === name && currentAuthors[i].email === email && currentAuthors[i].uri === uri){
  596. return true;
  597. }
  598. }
  599. return false;
  600. };
  601. authors = this._editors.authors.getValues();
  602. changed = false;
  603. for(i in authors){
  604. if(!searchAuthors(authors[i].name, authors[i].email, authors[i].uri)){
  605. changed = true;
  606. break;
  607. }
  608. }
  609. if(changed){
  610. entry.authors = [];
  611. for(i in authors){
  612. if(authors[i].name || authors[i].email || authors[i].uri){
  613. entry.addAuthor(authors[i].name, authors[i].email, authors[i].uri);
  614. }
  615. }
  616. modifiedEntry = true;
  617. }
  618. }
  619. }
  620. if(this._editors.contributors){
  621. if(modifiedEntry){
  622. entry.contributors = [];
  623. contributors = this._editors.contributors.getValues();
  624. for(i in contributors){
  625. if(contributors[i].name || contributors[i].email || contributors[i].uri){
  626. entry.addAuthor(contributors[i].name, contributors[i].email, contributors[i].uri);
  627. }
  628. }
  629. }else{
  630. var currentContributors = entry.contributors;
  631. var searchContributors = function(name, email, uri){
  632. for(i in currentContributors){
  633. if(currentContributors[i].name === name && currentContributors[i].email === email && currentContributors[i].uri === uri){
  634. return true;
  635. }
  636. }
  637. return false;
  638. };
  639. contributors = this._editors.contributors.getValues();
  640. changed = false;
  641. for(i in contributors){
  642. if(searchContributors(contributors[i].name, contributors[i].email, contributors[i].uri)){
  643. changed = true;
  644. break;
  645. }
  646. }
  647. if(changed){
  648. entry.contributors = [];
  649. for(i in contributors){
  650. if(contributors[i].name || contributors[i].email || contributors[i].uri){
  651. entry.addContributor(contributors[i].name, contributors[i].email, contributors[i].uri);
  652. }
  653. }
  654. modifiedEntry = true;
  655. }
  656. }
  657. }
  658. if(modifiedEntry){
  659. dojo.publish(this.entrySelectionTopic, [{action: "update", source: this, entry: entry, callback: this._handleSave }]);
  660. //TODO: REMOVE BELOW
  661. //var atomIO = new dojox.atom.io.Connection();
  662. //atomIO.updateEntry(entry, dojo.hitch(this,this._handleSave));
  663. //WARNING: Use above when testing with SimpleProxy (or any other servlet which
  664. // doesn't actually create a new entry and return it properly)
  665. //atomIO.updateEntry(entry, dojo.hitch(this,this._handleSave), true);
  666. }
  667. }else{
  668. this._new = false;
  669. entry = new dojox.atom.io.model.Entry();
  670. value = this._editors.title.attr('value');
  671. if(this.entryTitleSelect.value === "xhtml"){
  672. value = this._enforceXhtml(value);
  673. value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>';
  674. }
  675. entry.setTitle(value, this.entryTitleSelect.value);
  676. entry.id = this._editors.id.attr('value');
  677. authors = this._editors.authors.getValues();
  678. for(i in authors){
  679. if(authors[i].name || authors[i].email || authors[i].uri){
  680. entry.addAuthor(authors[i].name, authors[i].email, authors[i].uri);
  681. }
  682. }
  683. contributors = this._editors.contributors.getValues();
  684. for(i in contributors){
  685. if(contributors[i].name || contributors[i].email || contributors[i].uri){
  686. entry.addContributor(contributors[i].name, contributors[i].email, contributors[i].uri);
  687. }
  688. }
  689. value = this._editors.summary.attr('value');
  690. if(this.entrySummarySelect.value === "xhtml"){
  691. value = this._enforceXhtml(value);
  692. value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>';
  693. }
  694. entry.summary = new dojox.atom.io.model.Content("summary", value, null, this.entrySummarySelect.value);
  695. value = this._editors.content.attr('value');
  696. if(this.entryContentSelect.value === "xhtml"){
  697. value = this._enforceXhtml(value);
  698. value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>';
  699. }
  700. entry.content = new dojox.atom.io.model.Content("content", value, null, this.entryContentSelect.value);
  701. dojo.style(this.entryNewButton, 'display', '');
  702. dojo.publish(this.entrySelectionTopic, [{action: "post", source: this, entry: entry }]);
  703. }
  704. this._editMode = false;
  705. //Rebuild the view using the same entry and feed.
  706. this.setEntry(entry, this._feed, true);
  707. },
  708. _handleSave: function(/*object*/entry, /*string*/location){
  709. // summary:
  710. // Function for handling the save of an entry, cleaning up the display after the edit is completed.
  711. // description:
  712. // Function for handling the save of an entry, cleaning up the display after the edit is completed.
  713. //
  714. // entry: dojox.atom.io.model.Entry object
  715. // The entry that was saved.
  716. // Location: String
  717. // A URL to be used, not used here, but part of the call back from the AtomIO
  718. // returns:
  719. // Nothing.
  720. //Close the editor and revert out.
  721. this._editMode = false;
  722. //Rebuild the view using the same entry and feed.
  723. this.clear();
  724. this.setEntry(entry, this.getFeed(), true);
  725. },
  726. cancelEdits: function(){
  727. // summary:
  728. // Cancels edits and reverts the editor to its previous state (display mode)
  729. // description:
  730. // Cancels edits and reverts the editor to its previous state (display mode)
  731. //
  732. // returns:
  733. // Nothing.
  734. this._new = false;
  735. dojo.style(this.entrySaveCancelButtons, 'display', 'none');
  736. if(this._editable){
  737. dojo.style(this.entryEditButton, 'display', '');
  738. }
  739. dojo.style(this.entryNewButton, 'display', '');
  740. this._editMode = false;
  741. //Rebuild the view using the same entry and feed.
  742. this.clearEditors();
  743. this.setEntry(this.getEntry(), this.getFeed(), true);
  744. },
  745. clear: function(){
  746. // summary:
  747. // Clears the editor, destorys all editors, leaving the editor completely clear
  748. // description:
  749. // Clears the editor, destorys all editors, leaving the editor completely clear
  750. this._editable=false;
  751. this.clearEditors();
  752. dojox.atom.widget.FeedEntryEditor.superclass.clear.apply(this);
  753. if(this._contentEditor){
  754. // Note that the superclass clear destroys the widget since it's in the child widget list,
  755. // so this is just ref clearing.
  756. this._contentEditor = this._setObject = this._oldContent = this._contentEditorCreator = null;
  757. this._editors = {};
  758. }
  759. },
  760. clearEditors: function(){
  761. for(var key in this._editors){
  762. if(this._editors[key].declaredClass === "dijit.Editor"){
  763. this._editors[key].close(false, true);
  764. }
  765. this._editors[key].destroy();
  766. }
  767. this._editors = {};
  768. },
  769. _enforceXhtml: function(/*string*/html){
  770. // summary:
  771. // Function for cleaning up/enforcing the XHTML standard in HTML returned from the editor2 widget.
  772. // description:
  773. // Function for cleaning up/enforcing the XHTML standard in HTML returned from the editor2 widget.
  774. //
  775. // html:
  776. // HTML string to be enforced as xhtml.
  777. //
  778. // returns:
  779. // string of cleaned up HTML.
  780. var xhtml = null;
  781. if(html){
  782. //Handle <BR>
  783. var brRegExp = /<br>/g;
  784. xhtml = html.replace(brRegExp, "<br/>");
  785. //Handle <HR>
  786. xhtml = this._closeTag(xhtml, "hr");
  787. //Handle <img>
  788. xhtml = this._closeTag(xhtml, "img");
  789. }
  790. return xhtml;
  791. },
  792. _closeTag: function(/*string*/xhtml, /*string*/tag){
  793. // summary:
  794. // Function for closing tags in a text of HTML/XHTML
  795. // description:
  796. // Function for closing tags in a text of HTML/XHTML
  797. //
  798. // xhtml: String
  799. // XHTML string which needs the closing tag.
  800. // tag:
  801. // The tag to close.
  802. //
  803. // returns: string of cleaned up HTML.
  804. //
  805. // NOTE: Probably should redo this function in a more efficient way. This could get expensive.
  806. var tagStart = "<" + tag;
  807. var tagIndex = xhtml.indexOf(tagStart);
  808. if(tagIndex !== -1){
  809. while (tagIndex !== -1){
  810. var tempString = "";
  811. var foundTagEnd = false;
  812. for (var i = 0; i < xhtml.length; i++){
  813. var c = xhtml.charAt(i);
  814. if(i <= tagIndex ||foundTagEnd){
  815. tempString += c;
  816. }
  817. else
  818. {
  819. if(c === '>'){
  820. tempString += "/";
  821. foundTagEnd = true;
  822. }
  823. tempString +=c;
  824. }
  825. }
  826. xhtml = tempString;
  827. tagIndex = xhtml.indexOf(tagStart, tagIndex + 1);
  828. }
  829. }
  830. return xhtml;
  831. },
  832. _toggleNew: function(){
  833. // summary:
  834. // Function to put the editor into a state to create a new entry.
  835. // description:
  836. // Function to put the editor into a state to create a new entry.
  837. // Hide the edit/new buttons and show the save/cancel buttons.
  838. dojo.style(this.entryNewButton, 'display', 'none');
  839. dojo.style(this.entryEditButton, 'display', 'none');
  840. dojo.style(this.entrySaveCancelButtons, 'display', '');
  841. // Reset the type select boxes to text.
  842. this.entrySummarySelect.value = "text";
  843. this.entryContentSelect.value = "text";
  844. this.entryTitleSelect.value = "text";
  845. // Clear all nodes.
  846. this.clearNodes();
  847. this._new = true;
  848. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
  849. // Create all headers and editors.
  850. var titleHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.title});
  851. this.entryTitleHeader.appendChild(titleHeader.domNode);
  852. this._editors.title = this._createEditor(this.entryTitleNode, null);
  853. this.setFieldValidity("title",true);
  854. var authorHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.authors});
  855. this.entryAuthorHeader.appendChild(authorHeader.domNode);
  856. this._editors.authors = this._createPeopleEditor(this.entryAuthorNode, {name: "Author"});
  857. this.setFieldValidity("authors", true);
  858. var contributorHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.contributors});
  859. this.entryContributorHeader.appendChild(contributorHeader.domNode);
  860. this._editors.contributors = this._createPeopleEditor(this.entryContributorNode, {name: "Contributor"});
  861. this.setFieldValidity("contributors", true);
  862. var idHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.id});
  863. this.entryIdHeader.appendChild(idHeader.domNode);
  864. this._editors.id = this._createEditor(this.entryIdNode, null);
  865. this.setFieldValidity("id",true);
  866. var updatedHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.updated});
  867. this.entryUpdatedHeader.appendChild(updatedHeader.domNode);
  868. this._editors.updated = this._createEditor(this.entryUpdatedNode, null);
  869. this.setFieldValidity("updated",true);
  870. var summaryHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.summary});
  871. this.entrySummaryHeader.appendChild(summaryHeader.domNode);
  872. this._editors.summary = this._createEditor(this.entrySummaryNode, null, true);
  873. this.setFieldValidity("summaryedit",true);
  874. this.setFieldValidity("summary",true);
  875. var contentHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.content});
  876. this.entryContentHeader.appendChild(contentHeader.domNode);
  877. this._editors.content = this._createEditor(this.entryContentNode, null, true);
  878. this.setFieldValidity("contentedit",true);
  879. this.setFieldValidity("content",true);
  880. // Show the sections.
  881. this._displaySections();
  882. },
  883. _displaySections: function(){
  884. // summary: Function to display the appropriate sections based on validity.
  885. // description: Function to display the appropriate sections based on validity.
  886. // Hide select boxes.
  887. dojo.style(this.entrySummarySelect, 'display', 'none');
  888. dojo.style(this.entryContentSelect, 'display', 'none');
  889. dojo.style(this.entryTitleSelect, 'display', 'none');
  890. // Show select boxes if the flags are set.
  891. if(this.isFieldValid("contentedit")){
  892. dojo.style(this.entryContentSelect, 'display', '');
  893. }
  894. if(this.isFieldValid("summaryedit")){
  895. dojo.style(this.entrySummarySelect, 'display', '');
  896. }
  897. if(this.isFieldValid("titleedit")){
  898. dojo.style(this.entryTitleSelect, 'display', '');
  899. }
  900. // Call super's _displaySections.
  901. dojox.atom.widget.FeedEntryEditor.superclass._displaySections.apply(this);
  902. // If we have editors to load after the nodes are created on the page, execute those now.
  903. if(this._toLoad){
  904. for(var i in this._toLoad){
  905. var editor;
  906. if(this._toLoad[i].generateEditor){
  907. editor = dojo.hitch(this._toLoad[i], this._toLoad[i].generateEditor)();
  908. }else{
  909. editor = this._toLoad[i];
  910. }
  911. this._editors[this._toLoad[i].name] = editor;
  912. this._toLoad[i] = null;
  913. }
  914. this._toLoad = null;
  915. }
  916. }
  917. });
  918. dojo.declare("dojox.atom.widget.PeopleEditor",[dijit._Widget, dijit._Templated, dijit._Container],{
  919. // summary:
  920. // An editor for dojox.atom.io.model.Person objects.
  921. // description:
  922. // An editor for dojox.atom.io.model.Person objects. Displays multiple rows for the respective arrays
  923. // of people. Can add/remove rows on the fly.
  924. templateString: dojo.cache("dojox.atom", "widget/templates/PeopleEditor.html", "<div class=\"peopleEditor\">\n\t<table style=\"width: 100%\">\n\t\t<tbody dojoAttachPoint=\"peopleEditorEditors\"></tbody>\n\t</table>\n\t<span class=\"peopleEditorButton\" dojoAttachPoint=\"peopleEditorButton\" dojoAttachEvent=\"onclick:_add\"></span>\n</div>\n"),
  925. _rows: [],
  926. _editors: [],
  927. _index: 0,
  928. _numRows: 0,
  929. postCreate: function(){
  930. // Initializer function for the PeopleEditor widget.
  931. var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "PeopleEditor");
  932. if(this.name){
  933. if(this.name == "Author"){
  934. this.peopleEditorButton.appendChild(document.createTextNode("["+_nlsResources.addAuthor+"]"));
  935. }else if(this.name == "Contributor"){
  936. this.peopleEditorButton.appendChild(document.createTextNode("["+_nlsResources.addContributor+"]"));
  937. }
  938. }else{
  939. this.peopleEditorButton.appendChild(document.createTextNode("["+_nlsResources.add+"]"));
  940. }
  941. this._editors = [];
  942. if(!this.data || this.data.length===0){
  943. this._createEditors(null, null, null, 0, this.name);
  944. this._index = 1;
  945. }else{
  946. for(var i in this.data){
  947. this._createEditors(this.data[i].name, this.data[i].email, this.data[i].uri, i);
  948. this._index++;
  949. this._numRows++;
  950. }
  951. }
  952. },
  953. destroy: function(){
  954. for(var key in this._editors){
  955. for(var key2 in this._editors[key]){
  956. this._editors[key][key2].destroy();
  957. }
  958. }
  959. this._editors = [];
  960. },
  961. _createEditors: function(/*string*/name, /*string*/email, /*string*/uri, /*int*/index, /*string*/widgetName){
  962. // summary:
  963. // creates editor boxes (textbox widgets) for the individual values of a Person.
  964. // description:
  965. // creates editor boxes (textbox widgets) for the individual values of a Person.
  966. //
  967. // name:
  968. // The name of this Person.
  969. // email:
  970. // The email of this Person.
  971. // uri:
  972. // The Person's URI.
  973. // index:
  974. // The row index to use for this Person.
  975. var row = document.createElement("tr");
  976. this.peopleEditorEditors.appendChild(row);
  977. row.id = "removeRow"+index;
  978. var node = document.createElement("td");
  979. node.setAttribute('align', 'right');
  980. row.appendChild(node);
  981. node.colSpan = 2;
  982. if(this._numRows>0){
  983. var hr = document.createElement("hr");
  984. node.appendChild(hr);
  985. hr.id = "hr"+index;
  986. }
  987. row = document.createElement("span");
  988. node.appendChild(row);
  989. row.className = "peopleEditorButton";
  990. dojo.style(row, 'font-size', 'x-small');
  991. dojo.connect(row, "onclick", this, "_removeEditor");
  992. row.id = "remove"+index;
  993. node = document.createTextNode("[X]");
  994. row.appendChild(node);
  995. row = document.createElement("tr");
  996. this.peopleEditorEditors.appendChild(row);
  997. row.id = "editorsRow"+index;
  998. var labelNode = document.createElement("td");
  999. row.appendChild(labelNode);
  1000. dojo.style(labelNode, 'width', '20%');
  1001. node = document.createElement("td");
  1002. row.appendChild(node);
  1003. row = document.createElement("table");
  1004. labelNode.appendChild(row);
  1005. dojo.style(row, 'width', '100%');
  1006. labelNode = document.createElement("tbody");
  1007. row.appendChild(labelNode);
  1008. row = document.createElement("table");
  1009. node.appendChild(row);
  1010. dojo.style(row, 'width', '100%');
  1011. node = document.createElement("tbody");
  1012. row.appendChild(node);
  1013. this._editors[index] = [];
  1014. this._editors[index].push(this._createEditor(name, widgetName+'name'+index, 'Name:', labelNode, node));
  1015. this._editors[index].push(this._createEditor(email, widgetName+'email'+index, 'Email:', labelNode, node));
  1016. this._editors[index].push(this._createEditor(uri, widgetName+'uri'+index, 'URI:', labelNode, node));
  1017. },
  1018. _createEditor: function(/*string*/value, /*string*/id, /*string*/name, /*DOM node*/labelNode, /*DOM node*/node){
  1019. // summary:
  1020. // Creates an individual editor widget (textbox) for a value.
  1021. // description:
  1022. // Creates an individual editor widget (textbox) for a value.
  1023. //
  1024. // value:
  1025. // The initial value of the textbox
  1026. // id:
  1027. // The id the textbox should have.
  1028. // name:
  1029. // The text to put in the label element for this textbox.
  1030. // labelNode:
  1031. // The node to attach the label to.
  1032. // node:
  1033. // The node to attach the editor rows to.
  1034. //
  1035. // returns:
  1036. // Editor widget.
  1037. var row = document.createElement("tr");
  1038. labelNode.appendChild(row);
  1039. var label = document.createElement("label");
  1040. label.setAttribute('for', id);
  1041. label.appendChild(document.createTextNode(name));
  1042. labelNode = document.createElement("td");
  1043. labelNode.appendChild(label);
  1044. row.appendChild(labelNode);
  1045. row = document.createElement("tr");
  1046. node.appendChild(row);
  1047. node = document.createElement("td");
  1048. row.appendChild(node);
  1049. var viewNode = document.createElement("input");
  1050. viewNode.setAttribute('id', id);
  1051. node.appendChild(viewNode);
  1052. dojo.style(viewNode, 'width', '95%');
  1053. var box = new dijit.form.TextBox({},viewNode);
  1054. box.attr('value', value);
  1055. return box;
  1056. },
  1057. _removeEditor: function(/*object*/event){
  1058. // summary:
  1059. // Removes a Person from our list of editors.
  1060. // description:
  1061. // Removes a Person from our list of editors by removing the block of editors that
  1062. // make up that Person.
  1063. //
  1064. // event:
  1065. // The event generated when the remove button is pressed on the page.
  1066. var target = null;
  1067. if(dojo.isIE){
  1068. target = event.srcElement;
  1069. }else{
  1070. target = event.target;
  1071. }
  1072. var id = target.id;
  1073. id = id.substring(6);
  1074. for(var key in this._editors[id]){
  1075. this._editors[id][key].destroy();
  1076. }
  1077. var node = dojo.byId("editorsRow"+id);
  1078. var parent = node.parentNode;
  1079. parent.removeChild(node);
  1080. node = dojo.byId("removeRow"+id);
  1081. parent = node.parentNode;
  1082. parent.removeChild(node);
  1083. this._numRows--;
  1084. if(this._numRows === 1 && parent.firstChild.firstChild.firstChild.tagName.toLowerCase() === "hr"){
  1085. node = parent.firstChild.firstChild;
  1086. node.removeChild(node.firstChild);
  1087. }
  1088. this._editors[id] = null;
  1089. },
  1090. _add: function(){
  1091. // summary:
  1092. // Adds a new block of blank editors to represent a Person.
  1093. // description:
  1094. // Adds a new block of blank editors to represent a Person.
  1095. this._createEditors(null, null, null, this._index);
  1096. this._index++;
  1097. this._numRows++;
  1098. },
  1099. getValues: function(){
  1100. // summary:
  1101. // Gets the values of this editor in an array.
  1102. // description:
  1103. // Gets the values of this editor in an array, with each Person as an object within the array.
  1104. //
  1105. // returns:
  1106. // An array of anonymous objects representing dojox.atom.io.model.Persons.
  1107. var values = [];
  1108. for(var i in this._editors){
  1109. if(this._editors[i]){
  1110. values.push({name: this._editors[i][0].attr('value'), email: this._editors[i][1].attr('value'), uri: this._editors[i][2].attr('value')});
  1111. }
  1112. }
  1113. return values;
  1114. }
  1115. });
  1116. }