FeedEntryEditor.js 53 KB

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