entry.summary = new dojox.atom.io.model.Content("summary", value, null, this.entrySummarySelect.value);
if(this._editors.content && (this._editors.content.attr('value') != entry.content.value || this.entryContentSelect.value != entry.content.type)){
') !== 0){
value = '
' + value + '
';
}
}
entry.content = new dojox.atom.io.model.Content("content", value, null, this.entryContentSelect.value);
modifiedEntry = true;
}
if(this._editors.authors){
if(modifiedEntry){
entry.authors = [];
authors = this._editors.authors.getValues();
for(i in authors){
if(authors[i].name || authors[i].email || authors[i].uri){
entry.addAuthor(authors[i].name, authors[i].email, authors[i].uri);
}
}
}else{
var currentAuthors = entry.authors;
var searchAuthors = function(name, email, uri){
for(i in currentAuthors){
if(currentAuthors[i].name === name && currentAuthors[i].email === email && currentAuthors[i].uri === uri){
return true;
}
}
return false;
};
authors = this._editors.authors.getValues();
changed = false;
for(i in authors){
if(!searchAuthors(authors[i].name, authors[i].email, authors[i].uri)){
changed = true;
break;
}
}
if(changed){
entry.authors = [];
for(i in authors){
if(authors[i].name || authors[i].email || authors[i].uri){
entry.addAuthor(authors[i].name, authors[i].email, authors[i].uri);
}
}
modifiedEntry = true;
}
}
}
if(this._editors.contributors){
if(modifiedEntry){
entry.contributors = [];
contributors = this._editors.contributors.getValues();
for(i in contributors){
if(contributors[i].name || contributors[i].email || contributors[i].uri){
entry.addAuthor(contributors[i].name, contributors[i].email, contributors[i].uri);
}
}
}else{
var currentContributors = entry.contributors;
var searchContributors = function(name, email, uri){
for(i in currentContributors){
if(currentContributors[i].name === name && currentContributors[i].email === email && currentContributors[i].uri === uri){
return true;
}
}
return false;
};
contributors = this._editors.contributors.getValues();
changed = false;
for(i in contributors){
if(searchContributors(contributors[i].name, contributors[i].email, contributors[i].uri)){
changed = true;
break;
}
}
if(changed){
entry.contributors = [];
for(i in contributors){
if(contributors[i].name || contributors[i].email || contributors[i].uri){
entry.addContributor(contributors[i].name, contributors[i].email, contributors[i].uri);
}
}
modifiedEntry = true;
}
}
}
if(modifiedEntry){
dojo.publish(this.entrySelectionTopic, [{action: "update", source: this, entry: entry, callback: this._handleSave }]);
//TODO: REMOVE BELOW
//var atomIO = new dojox.atom.io.Connection();
//atomIO.updateEntry(entry, dojo.hitch(this,this._handleSave));
//WARNING: Use above when testing with SimpleProxy (or any other servlet which
// doesn't actually create a new entry and return it properly)
//atomIO.updateEntry(entry, dojo.hitch(this,this._handleSave), true);
}
}else{
this._new = false;
entry = new dojox.atom.io.model.Entry();
value = this._editors.title.attr('value');
if(this.entryTitleSelect.value === "xhtml"){
value = this._enforceXhtml(value);
value = '
' + value + '
';
}
entry.setTitle(value, this.entryTitleSelect.value);
entry.id = this._editors.id.attr('value');
authors = this._editors.authors.getValues();
for(i in authors){
if(authors[i].name || authors[i].email || authors[i].uri){
entry.addAuthor(authors[i].name, authors[i].email, authors[i].uri);
}
}
contributors = this._editors.contributors.getValues();
for(i in contributors){
if(contributors[i].name || contributors[i].email || contributors[i].uri){
entry.addContributor(contributors[i].name, contributors[i].email, contributors[i].uri);
}
}
value = this._editors.summary.attr('value');
if(this.entrySummarySelect.value === "xhtml"){
value = this._enforceXhtml(value);
value = '
' + value + '
';
}
entry.summary = new dojox.atom.io.model.Content("summary", value, null, this.entrySummarySelect.value);
value = this._editors.content.attr('value');
if(this.entryContentSelect.value === "xhtml"){
value = this._enforceXhtml(value);
value = '
' + value + '
';
}
entry.content = new dojox.atom.io.model.Content("content", value, null, this.entryContentSelect.value);
dojo.style(this.entryNewButton, 'display', '');
dojo.publish(this.entrySelectionTopic, [{action: "post", source: this, entry: entry }]);
}
this._editMode = false;
//Rebuild the view using the same entry and feed.
this.setEntry(entry, this._feed, true);
},
_handleSave: function(/*object*/entry, /*string*/location){
// summary:
// Function for handling the save of an entry, cleaning up the display after the edit is completed.
// description:
// Function for handling the save of an entry, cleaning up the display after the edit is completed.
//
// entry: dojox.atom.io.model.Entry object
// The entry that was saved.
// Location: String
// A URL to be used, not used here, but part of the call back from the AtomIO
// returns:
// Nothing.
//Close the editor and revert out.
this._editMode = false;
//Rebuild the view using the same entry and feed.
this.clear();
this.setEntry(entry, this.getFeed(), true);
},
cancelEdits: function(){
// summary:
// Cancels edits and reverts the editor to its previous state (display mode)
// description:
// Cancels edits and reverts the editor to its previous state (display mode)
//
// returns:
// Nothing.
this._new = false;
dojo.style(this.entrySaveCancelButtons, 'display', 'none');
if(this._editable){
dojo.style(this.entryEditButton, 'display', '');
}
dojo.style(this.entryNewButton, 'display', '');
this._editMode = false;
//Rebuild the view using the same entry and feed.
this.clearEditors();
this.setEntry(this.getEntry(), this.getFeed(), true);
},
clear: function(){
// summary:
// Clears the editor, destorys all editors, leaving the editor completely clear
// description:
// Clears the editor, destorys all editors, leaving the editor completely clear
this._editable=false;
this.clearEditors();
dojox.atom.widget.FeedEntryEditor.superclass.clear.apply(this);
if(this._contentEditor){
// Note that the superclass clear destroys the widget since it's in the child widget list,
// so this is just ref clearing.
this._contentEditor = this._setObject = this._oldContent = this._contentEditorCreator = null;
this._editors = {};
}
},
clearEditors: function(){
for(var key in this._editors){
if(this._editors[key].declaredClass === "dijit.Editor"){
this._editors[key].close(false, true);
}
this._editors[key].destroy();
}
this._editors = {};
},
_enforceXhtml: function(/*string*/html){
// summary:
// Function for cleaning up/enforcing the XHTML standard in HTML returned from the editor2 widget.
// description:
// Function for cleaning up/enforcing the XHTML standard in HTML returned from the editor2 widget.
//
// html:
// HTML string to be enforced as xhtml.
//
// returns:
// string of cleaned up HTML.
var xhtml = null;
if(html){
//Handle
var brRegExp = /
/g;
xhtml = html.replace(brRegExp, "
");
//Handle
xhtml = this._closeTag(xhtml, "hr");
//Handle
![]()
xhtml = this._closeTag(xhtml, "img");
}
return xhtml;
},
_closeTag: function(/*string*/xhtml, /*string*/tag){
// summary:
// Function for closing tags in a text of HTML/XHTML
// description:
// Function for closing tags in a text of HTML/XHTML
//
// xhtml: String
// XHTML string which needs the closing tag.
// tag:
// The tag to close.
//
// returns: string of cleaned up HTML.
//
// NOTE: Probably should redo this function in a more efficient way. This could get expensive.
var tagStart = "<" + tag;
var tagIndex = xhtml.indexOf(tagStart);
if(tagIndex !== -1){
while (tagIndex !== -1){
var tempString = "";
var foundTagEnd = false;
for (var i = 0; i < xhtml.length; i++){
var c = xhtml.charAt(i);
if(i <= tagIndex ||foundTagEnd){
tempString += c;
}
else
{
if(c === '>'){
tempString += "/";
foundTagEnd = true;
}
tempString +=c;
}
}
xhtml = tempString;
tagIndex = xhtml.indexOf(tagStart, tagIndex + 1);
}
}
return xhtml;
},
_toggleNew: function(){
// summary:
// Function to put the editor into a state to create a new entry.
// description:
// Function to put the editor into a state to create a new entry.
// Hide the edit/new buttons and show the save/cancel buttons.
dojo.style(this.entryNewButton, 'display', 'none');
dojo.style(this.entryEditButton, 'display', 'none');
dojo.style(this.entrySaveCancelButtons, 'display', '');
// Reset the type select boxes to text.
this.entrySummarySelect.value = "text";
this.entryContentSelect.value = "text";
this.entryTitleSelect.value = "text";
// Clear all nodes.
this.clearNodes();
this._new = true;
var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "FeedEntryViewer");
// Create all headers and editors.
var titleHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.title});
this.entryTitleHeader.appendChild(titleHeader.domNode);
this._editors.title = this._createEditor(this.entryTitleNode, null);
this.setFieldValidity("title",true);
var authorHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.authors});
this.entryAuthorHeader.appendChild(authorHeader.domNode);
this._editors.authors = this._createPeopleEditor(this.entryAuthorNode, {name: "Author"});
this.setFieldValidity("authors", true);
var contributorHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.contributors});
this.entryContributorHeader.appendChild(contributorHeader.domNode);
this._editors.contributors = this._createPeopleEditor(this.entryContributorNode, {name: "Contributor"});
this.setFieldValidity("contributors", true);
var idHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.id});
this.entryIdHeader.appendChild(idHeader.domNode);
this._editors.id = this._createEditor(this.entryIdNode, null);
this.setFieldValidity("id",true);
var updatedHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.updated});
this.entryUpdatedHeader.appendChild(updatedHeader.domNode);
this._editors.updated = this._createEditor(this.entryUpdatedNode, null);
this.setFieldValidity("updated",true);
var summaryHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.summary});
this.entrySummaryHeader.appendChild(summaryHeader.domNode);
this._editors.summary = this._createEditor(this.entrySummaryNode, null, true);
this.setFieldValidity("summaryedit",true);
this.setFieldValidity("summary",true);
var contentHeader = new dojox.atom.widget.EntryHeader({title: _nlsResources.content});
this.entryContentHeader.appendChild(contentHeader.domNode);
this._editors.content = this._createEditor(this.entryContentNode, null, true);
this.setFieldValidity("contentedit",true);
this.setFieldValidity("content",true);
// Show the sections.
this._displaySections();
},
_displaySections: function(){
// summary: Function to display the appropriate sections based on validity.
// description: Function to display the appropriate sections based on validity.
// Hide select boxes.
dojo.style(this.entrySummarySelect, 'display', 'none');
dojo.style(this.entryContentSelect, 'display', 'none');
dojo.style(this.entryTitleSelect, 'display', 'none');
// Show select boxes if the flags are set.
if(this.isFieldValid("contentedit")){
dojo.style(this.entryContentSelect, 'display', '');
}
if(this.isFieldValid("summaryedit")){
dojo.style(this.entrySummarySelect, 'display', '');
}
if(this.isFieldValid("titleedit")){
dojo.style(this.entryTitleSelect, 'display', '');
}
// Call super's _displaySections.
dojox.atom.widget.FeedEntryEditor.superclass._displaySections.apply(this);
// If we have editors to load after the nodes are created on the page, execute those now.
if(this._toLoad){
for(var i in this._toLoad){
var editor;
if(this._toLoad[i].generateEditor){
editor = dojo.hitch(this._toLoad[i], this._toLoad[i].generateEditor)();
}else{
editor = this._toLoad[i];
}
this._editors[this._toLoad[i].name] = editor;
this._toLoad[i] = null;
}
this._toLoad = null;
}
}
});
dojo.declare("dojox.atom.widget.PeopleEditor",[dijit._Widget, dijit._Templated, dijit._Container],{
// summary:
// An editor for dojox.atom.io.model.Person objects.
// description:
// An editor for dojox.atom.io.model.Person objects. Displays multiple rows for the respective arrays
// of people. Can add/remove rows on the fly.
templateString: dojo.cache("dojox.atom", "widget/templates/PeopleEditor.html"),
_rows: [],
_editors: [],
_index: 0,
_numRows: 0,
postCreate: function(){
// Initializer function for the PeopleEditor widget.
var _nlsResources = dojo.i18n.getLocalization("dojox.atom.widget", "PeopleEditor");
if(this.name){
if(this.name == "Author"){
this.peopleEditorButton.appendChild(document.createTextNode("["+_nlsResources.addAuthor+"]"));
}else if(this.name == "Contributor"){
this.peopleEditorButton.appendChild(document.createTextNode("["+_nlsResources.addContributor+"]"));
}
}else{
this.peopleEditorButton.appendChild(document.createTextNode("["+_nlsResources.add+"]"));
}
this._editors = [];
if(!this.data || this.data.length===0){
this._createEditors(null, null, null, 0, this.name);
this._index = 1;
}else{
for(var i in this.data){
this._createEditors(this.data[i].name, this.data[i].email, this.data[i].uri, i);
this._index++;
this._numRows++;
}
}