| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/lang", |
| 4 |
"dojo/_base/connect", |
| 5 |
"dojo/_base/declare", |
| 6 |
"dojo/_base/fx", |
| 7 |
"dojo/_base/sniff", |
| 8 |
"dojo/dom", |
| 9 |
"dojo/dom-style", |
| 10 |
"dojo/dom-construct", |
| 11 |
"dijit/_Widget", |
| 12 |
"dijit/_Templated", |
| 13 |
"dijit/_Container", |
| 14 |
"dijit/Editor", |
| 15 |
"dijit/form/TextBox", |
| 16 |
"dijit/form/SimpleTextarea", |
| 17 |
"./FeedEntryViewer", |
| 18 |
"../io/model", |
| 19 |
"dojo/text!./templates/FeedEntryEditor.html", |
| 20 |
"dojo/text!./templates/PeopleEditor.html", |
| 21 |
"dojo/i18n!./nls/FeedEntryViewer", |
| 22 |
"dojo/i18n!./nls/FeedEntryEditor", |
| 23 |
"dojo/i18n!./nls/PeopleEditor" |
| 24 |
], function (dojo, lang, connect, declare, fx, has, domUtil, domStyle, domConstruct, |
| 25 |
_Widget, _Templated, _Container, Editor, TextBox, SimpleTextarea, |
| 26 |
FeedEntryViewer, model, template, peopleEditorTemplate, i18nViewer, i18nEditor, i18nPeople) { |
| 27 |
dojo.experimental("dojox.atom.widget.FeedEntryEditor"); |
| 28 |
|
| 29 |
|
| 30 |
var FeedEntryEditor = declare("dojox.atom.widget.FeedEntryEditor", FeedEntryViewer,{ |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
_contentEditor: null, |
| 35 |
_oldContent: null, |
| 36 |
_setObject: null, |
| 37 |
enableEdit: false, |
| 38 |
_contentEditorCreator: null, |
| 39 |
_editors: {}, |
| 40 |
entryNewButton: null, |
| 41 |
_editable: false, |
| 42 |
|
| 43 |
|
| 44 |
templateString: template, |
| 45 |
|
| 46 |
postCreate: function(){ |
| 47 |
if(this.entrySelectionTopic !== ""){ |
| 48 |
this._subscriptions = [dojo.subscribe(this.entrySelectionTopic, this, "_handleEvent")]; |
| 49 |
} |
| 50 |
var _nlsResources = i18nViewer; |
| 51 |
this.displayOptions.innerHTML = _nlsResources.displayOptions; |
| 52 |
this.feedEntryCheckBoxLabelTitle.innerHTML = _nlsResources.title; |
| 53 |
this.feedEntryCheckBoxLabelAuthors.innerHTML = _nlsResources.authors; |
| 54 |
this.feedEntryCheckBoxLabelContributors.innerHTML = _nlsResources.contributors; |
| 55 |
this.feedEntryCheckBoxLabelId.innerHTML = _nlsResources.id; |
| 56 |
this.close.innerHTML = _nlsResources.close; |
| 57 |
this.feedEntryCheckBoxLabelUpdated.innerHTML = _nlsResources.updated; |
| 58 |
this.feedEntryCheckBoxLabelSummary.innerHTML = _nlsResources.summary; |
| 59 |
this.feedEntryCheckBoxLabelContent.innerHTML = _nlsResources.content; |
| 60 |
|
| 61 |
_nlsResources = i18nEditor; |
| 62 |
this.doNew.innerHTML = _nlsResources.doNew; |
| 63 |
this.edit.innerHTML = _nlsResources.edit; |
| 64 |
this.save.innerHTML = _nlsResources.save; |
| 65 |
this.cancel.innerHTML = _nlsResources.cancel; |
| 66 |
}, |
| 67 |
|
| 68 |
setEntry: function(entry, feed, leaveMenuState){ |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
if(this._entry !== entry){ |
| 74 |
|
| 75 |
this._editMode=false; |
| 76 |
leaveMenuState=false; |
| 77 |
}else{ |
| 78 |
leaveMenuState = true; |
| 79 |
} |
| 80 |
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 |
|
| 90 |
if(this.enableMenuFade && this.entrySaveCancelButton){ |
| 91 |
fx.fadeOut({node: this.entrySaveCancelButton,duration: 250}).play(); |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
}, |
| 96 |
|
| 97 |
_toggleEdit: function(){ |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
if(this._editable && this.enableEdit){ |
| 103 |
domStyle.set(this.entryEditButton, 'display', 'none'); |
| 104 |
domStyle.set(this.entrySaveCancelButtons, 'display', ''); |
| 105 |
this._editMode = true; |
| 106 |
|
| 107 |
|
| 108 |
this.setEntry(this._entry, this._feed, true); |
| 109 |
} |
| 110 |
}, |
| 111 |
|
| 112 |
_handleEvent: function(entrySelectionEvent){ |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
if(entrySelectionEvent.source != this && entrySelectionEvent.action == "delete" && |
| 120 |
entrySelectionEvent.entry && entrySelectionEvent.entry == this._entry){ |
| 121 |
domStyle.set(this.entryEditButton, 'display', 'none'); |
| 122 |
} |
| 123 |
FeedEntryEditor.superclass._handleEvent.call(this, entrySelectionEvent); |
| 124 |
}, |
| 125 |
|
| 126 |
_isEditable: function(entry){ |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
var retVal = false; |
| 137 |
if(entry && entry !== null && entry.links && entry.links !== null){ |
| 138 |
for(var x in entry.links){ |
| 139 |
if(entry.links[x].rel && entry.links[x].rel == "edit"){ |
| 140 |
retVal = true; |
| 141 |
break; |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
return retVal; |
| 146 |
}, |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
setTitle: function(titleAnchorNode, editMode, entry){ |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
if(!editMode){ |
| 164 |
FeedEntryEditor.superclass.setTitle.call(this, titleAnchorNode, editMode, entry); |
| 165 |
if(entry.title && entry.title.value && entry.title.value !== null){ |
| 166 |
this.setFieldValidity("title", true); |
| 167 |
} |
| 168 |
}else{ |
| 169 |
if(entry.title && entry.title.value && entry.title.value !== null){ |
| 170 |
if(!this._toLoad){ |
| 171 |
this._toLoad = []; |
| 172 |
} |
| 173 |
this.entryTitleSelect.value = entry.title.type; |
| 174 |
|
| 175 |
var editor = this._createEditor(titleAnchorNode, entry.title, true, entry.title.type === "html" || entry.title.type === "xhtml"); |
| 176 |
editor.name = "title"; |
| 177 |
this._toLoad.push(editor); |
| 178 |
this.setFieldValidity("titleedit",true); |
| 179 |
this.setFieldValidity("title",true); |
| 180 |
} |
| 181 |
} |
| 182 |
}, |
| 183 |
|
| 184 |
setAuthors: function(authorsAnchorNode, editMode, entry){ |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
if(!editMode){ |
| 197 |
FeedEntryEditor.superclass.setAuthors.call(this, authorsAnchorNode, editMode, entry); |
| 198 |
if(entry.authors && entry.authors.length > 0){ |
| 199 |
this.setFieldValidity("authors", true); |
| 200 |
} |
| 201 |
}else{ |
| 202 |
if(entry.authors && entry.authors.length > 0){ |
| 203 |
this._editors.authors = this._createPeopleEditor(this.entryAuthorNode, {data: entry.authors, name: "Author"}); |
| 204 |
this.setFieldValidity("authors", true); |
| 205 |
} |
| 206 |
} |
| 207 |
}, |
| 208 |
|
| 209 |
|
| 210 |
setContributors: function(contributorsAnchorNode, editMode, entry){ |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
if(!editMode){ |
| 223 |
FeedEntryEditor.superclass.setContributors.call(this, contributorsAnchorNode, editMode, entry); |
| 224 |
if(entry.contributors && entry.contributors.length > 0){ |
| 225 |
this.setFieldValidity("contributors", true); |
| 226 |
} |
| 227 |
}else{ |
| 228 |
if(entry.contributors && entry.contributors.length > 0){ |
| 229 |
this._editors.contributors = this._createPeopleEditor(this.entryContributorNode, {data: entry.contributors, name: "Contributor"}); |
| 230 |
this.setFieldValidity("contributors", true); |
| 231 |
} |
| 232 |
} |
| 233 |
}, |
| 234 |
|
| 235 |
|
| 236 |
setId: function(idAnchorNode, editMode, entry){ |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
if(!editMode){ |
| 249 |
FeedEntryEditor.superclass.setId.call(this, idAnchorNode, editMode, entry); |
| 250 |
if(entry.id && entry.id !== null){ |
| 251 |
this.setFieldValidity("id", true); |
| 252 |
} |
| 253 |
}else{ |
| 254 |
if(entry.id && entry.id !== null){ |
| 255 |
this._editors.id = this._createEditor(idAnchorNode, entry.id); |
| 256 |
this.setFieldValidity("id",true); |
| 257 |
} |
| 258 |
} |
| 259 |
}, |
| 260 |
|
| 261 |
setUpdated: function(updatedAnchorNode, editMode, entry){ |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
if(!editMode){ |
| 274 |
FeedEntryEditor.superclass.setUpdated.call(this, updatedAnchorNode, editMode, entry); |
| 275 |
if(entry.updated && entry.updated !== null){ |
| 276 |
this.setFieldValidity("updated", true); |
| 277 |
} |
| 278 |
}else{ |
| 279 |
if(entry.updated && entry.updated !== null){ |
| 280 |
this._editors.updated = this._createEditor(updatedAnchorNode, entry.updated); |
| 281 |
this.setFieldValidity("updated",true); |
| 282 |
} |
| 283 |
} |
| 284 |
}, |
| 285 |
|
| 286 |
|
| 287 |
setSummary: function(summaryAnchorNode, editMode, entry){ |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
if(!editMode){ |
| 300 |
FeedEntryEditor.superclass.setSummary.call(this, summaryAnchorNode, editMode, entry); |
| 301 |
if(entry.summary && entry.summary.value && entry.summary.value !== null){ |
| 302 |
this.setFieldValidity("summary", true); |
| 303 |
} |
| 304 |
}else{ |
| 305 |
if(entry.summary && entry.summary.value && entry.summary.value !== null){ |
| 306 |
if(!this._toLoad){ |
| 307 |
this._toLoad = []; |
| 308 |
} |
| 309 |
this.entrySummarySelect.value = entry.summary.type; |
| 310 |
|
| 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 |
|
| 320 |
setContent: function(contentAnchorNode, editMode, entry){ |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
if(!editMode){ |
| 333 |
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 |
|
| 352 |
_createEditor: function(anchorNode, node, multiline, rte){ |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
var viewNode; |
| 369 |
var box; |
| 370 |
if(!node){ |
| 371 |
if(rte){ |
| 372 |
|
| 373 |
|
| 374 |
return {anchorNode: anchorNode, |
| 375 |
entryValue: "", |
| 376 |
editor: null, |
| 377 |
generateEditor: function(){ |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
var node = document.createElement("div"); |
| 382 |
node.innerHTML = this.entryValue; |
| 383 |
this.anchorNode.appendChild(node); |
| 384 |
var _editor = new Editor({}, node); |
| 385 |
this.editor = _editor; |
| 386 |
return _editor; |
| 387 |
} |
| 388 |
}; |
| 389 |
} |
| 390 |
if(multiline){ |
| 391 |
|
| 392 |
viewNode = document.createElement("textarea"); |
| 393 |
anchorNode.appendChild(viewNode); |
| 394 |
domStyle.set(viewNode, 'width', '90%'); |
| 395 |
box = new SimpleTextarea({},viewNode); |
| 396 |
}else{ |
| 397 |
|
| 398 |
viewNode = document.createElement("input"); |
| 399 |
anchorNode.appendChild(viewNode); |
| 400 |
domStyle.set(viewNode, 'width', '95%'); |
| 401 |
box = new TextBox({},viewNode); |
| 402 |
} |
| 403 |
box.attr('value', ''); |
| 404 |
return box; |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
var value; |
| 409 |
if(node.value !== undefined){ |
| 410 |
value = node.value; |
| 411 |
}else if(node.attr){ |
| 412 |
value = node.attr('value'); |
| 413 |
}else{ |
| 414 |
value = node; |
| 415 |
} |
| 416 |
if(rte){ |
| 417 |
|
| 418 |
|
| 419 |
if(value.indexOf("<") != -1){ |
| 420 |
value = value.replace(/</g, "<"); |
| 421 |
} |
| 422 |
return {anchorNode: anchorNode, |
| 423 |
entryValue: value, |
| 424 |
editor: null, |
| 425 |
generateEditor: function(){ |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
var node = document.createElement("div"); |
| 430 |
node.innerHTML = this.entryValue; |
| 431 |
this.anchorNode.appendChild(node); |
| 432 |
var _editor = new Editor({}, node); |
| 433 |
this.editor = _editor; |
| 434 |
return _editor; |
| 435 |
} |
| 436 |
}; |
| 437 |
} |
| 438 |
if(multiline){ |
| 439 |
|
| 440 |
viewNode = document.createElement("textarea"); |
| 441 |
anchorNode.appendChild(viewNode); |
| 442 |
domStyle.set(viewNode, 'width', '90%'); |
| 443 |
box = new SimpleTextarea({},viewNode); |
| 444 |
}else{ |
| 445 |
|
| 446 |
viewNode = document.createElement("input"); |
| 447 |
anchorNode.appendChild(viewNode); |
| 448 |
domStyle.set(viewNode, 'width', '95%'); |
| 449 |
box = new TextBox({},viewNode); |
| 450 |
} |
| 451 |
box.attr('value', value); |
| 452 |
return box; |
| 453 |
}, |
| 454 |
|
| 455 |
_switchEditor: function(event){ |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
var type = null; |
| 464 |
var target = null; |
| 465 |
var parent = null; |
| 466 |
|
| 467 |
|
| 468 |
if(has("ie")){ |
| 469 |
target = event.srcElement; |
| 470 |
}else{ |
| 471 |
target = event.target; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 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 |
|
| 486 |
|
| 487 |
var editor = this._editors[type]; |
| 488 |
var newEditor; |
| 489 |
var value; |
| 490 |
|
| 491 |
if(target.value === "text"){ |
| 492 |
if(editor.isInstanceOf(Editor)){ |
| 493 |
|
| 494 |
|
| 495 |
value = editor.attr('value', false); |
| 496 |
editor.close(false,true); |
| 497 |
editor.destroy(); |
| 498 |
while(parent.firstChild){ |
| 499 |
domConstruct.destroy(parent.firstChild); |
| 500 |
} |
| 501 |
newEditor = this._createEditor(parent, {value: value}, true, false); |
| 502 |
this._editors[type] = newEditor; |
| 503 |
} |
| 504 |
}else{ |
| 505 |
if(!editor.isInstanceOf(Editor)){ |
| 506 |
|
| 507 |
|
| 508 |
value = editor.attr('value'); |
| 509 |
editor.destroy(); |
| 510 |
while(parent.firstChild){ |
| 511 |
domConstruct.destroy(parent.firstChild); |
| 512 |
} |
| 513 |
newEditor = this._createEditor(parent, {value: value}, true, true); |
| 514 |
newEditor = lang.hitch(newEditor, newEditor.generateEditor)(); |
| 515 |
this._editors[type] = newEditor; |
| 516 |
} |
| 517 |
} |
| 518 |
}, |
| 519 |
|
| 520 |
_createPeopleEditor: function(anchorNode, node){ |
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
var viewNode = document.createElement("div"); |
| 531 |
anchorNode.appendChild(viewNode); |
| 532 |
return new PeopleEditor(node,viewNode); |
| 533 |
}, |
| 534 |
|
| 535 |
saveEdits: function(){ |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 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 |
|
| 568 |
if(this._editors.id.attr('value') != entry.id){ |
| 569 |
entry.id = this._editors.id.attr('value'); |
| 570 |
modifiedEntry = true; |
| 571 |
} |
| 572 |
|
| 573 |
if(this._editors.summary && (this._editors.summary.attr('value') != entry.summary.value || this.entrySummarySelect.value != entry.summary.type)){ |
| 574 |
value = this._editors.summary.attr('value'); |
| 575 |
if(this.entrySummarySelect.value === "xhtml"){ |
| 576 |
value = this._enforceXhtml(value); |
| 577 |
if(value.indexOf('<div xmlns="http://www.w3.org/1999/xhtml">') !== 0){ |
| 578 |
value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>'; |
| 579 |
} |
| 580 |
} |
| 581 |
entry.summary = new model.Content("summary", value, null, this.entrySummarySelect.value); |
| 582 |
modifiedEntry = true; |
| 583 |
} |
| 584 |
|
| 585 |
if(this._editors.content && (this._editors.content.attr('value') != entry.content.value || this.entryContentSelect.value != entry.content.type)){ |
| 586 |
value = this._editors.content.attr('value'); |
| 587 |
if(this.entryContentSelect.value === "xhtml"){ |
| 588 |
value = this._enforceXhtml(value); |
| 589 |
if(value.indexOf('<div xmlns="http://www.w3.org/1999/xhtml">') !== 0){ |
| 590 |
value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>'; |
| 591 |
} |
| 592 |
} |
| 593 |
entry.content = new model.Content("content", value, null, this.entryContentSelect.value); |
| 594 |
modifiedEntry = true; |
| 595 |
} |
| 596 |
|
| 597 |
if(this._editors.authors){ |
| 598 |
if(modifiedEntry){ |
| 599 |
entry.authors = []; |
| 600 |
authors = this._editors.authors.getValues(); |
| 601 |
for(i in authors){ |
| 602 |
if(authors[i].name || authors[i].email || authors[i].uri){ |
| 603 |
entry.addAuthor(authors[i].name, authors[i].email, authors[i].uri); |
| 604 |
} |
| 605 |
} |
| 606 |
}else{ |
| 607 |
var currentAuthors = entry.authors; |
| 608 |
var searchAuthors = function(name, email, uri){ |
| 609 |
for(i in currentAuthors){ |
| 610 |
if(currentAuthors[i].name === name && currentAuthors[i].email === email && currentAuthors[i].uri === uri){ |
| 611 |
return true; |
| 612 |
} |
| 613 |
} |
| 614 |
return false; |
| 615 |
}; |
| 616 |
authors = this._editors.authors.getValues(); |
| 617 |
changed = false; |
| 618 |
for(i in authors){ |
| 619 |
if(!searchAuthors(authors[i].name, authors[i].email, authors[i].uri)){ |
| 620 |
changed = true; |
| 621 |
break; |
| 622 |
} |
| 623 |
} |
| 624 |
if(changed){ |
| 625 |
entry.authors = []; |
| 626 |
for(i in authors){ |
| 627 |
if(authors[i].name || authors[i].email || authors[i].uri){ |
| 628 |
entry.addAuthor(authors[i].name, authors[i].email, authors[i].uri); |
| 629 |
} |
| 630 |
} |
| 631 |
modifiedEntry = true; |
| 632 |
} |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
if(this._editors.contributors){ |
| 637 |
if(modifiedEntry){ |
| 638 |
entry.contributors = []; |
| 639 |
contributors = this._editors.contributors.getValues(); |
| 640 |
for(i in contributors){ |
| 641 |
if(contributors[i].name || contributors[i].email || contributors[i].uri){ |
| 642 |
entry.addAuthor(contributors[i].name, contributors[i].email, contributors[i].uri); |
| 643 |
} |
| 644 |
} |
| 645 |
}else{ |
| 646 |
var currentContributors = entry.contributors; |
| 647 |
var searchContributors = function(name, email, uri){ |
| 648 |
for(i in currentContributors){ |
| 649 |
if(currentContributors[i].name === name && currentContributors[i].email === email && currentContributors[i].uri === uri){ |
| 650 |
return true; |
| 651 |
} |
| 652 |
} |
| 653 |
return false; |
| 654 |
}; |
| 655 |
contributors = this._editors.contributors.getValues(); |
| 656 |
changed = false; |
| 657 |
for(i in contributors){ |
| 658 |
if(searchContributors(contributors[i].name, contributors[i].email, contributors[i].uri)){ |
| 659 |
changed = true; |
| 660 |
break; |
| 661 |
} |
| 662 |
} |
| 663 |
if(changed){ |
| 664 |
entry.contributors = []; |
| 665 |
for(i in contributors){ |
| 666 |
if(contributors[i].name || contributors[i].email || contributors[i].uri){ |
| 667 |
entry.addContributor(contributors[i].name, contributors[i].email, contributors[i].uri); |
| 668 |
} |
| 669 |
} |
| 670 |
modifiedEntry = true; |
| 671 |
} |
| 672 |
} |
| 673 |
} |
| 674 |
|
| 675 |
if(modifiedEntry){ |
| 676 |
dojo.publish(this.entrySelectionTopic, [{action: "update", source: this, entry: entry, callback: this._handleSave }]); |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
} |
| 684 |
}else{ |
| 685 |
this._new = false; |
| 686 |
entry = new model.Entry(); |
| 687 |
|
| 688 |
value = this._editors.title.attr('value'); |
| 689 |
if(this.entryTitleSelect.value === "xhtml"){ |
| 690 |
value = this._enforceXhtml(value); |
| 691 |
value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>'; |
| 692 |
} |
| 693 |
entry.setTitle(value, this.entryTitleSelect.value); |
| 694 |
entry.id = this._editors.id.attr('value'); |
| 695 |
|
| 696 |
authors = this._editors.authors.getValues(); |
| 697 |
for(i in authors){ |
| 698 |
if(authors[i].name || authors[i].email || authors[i].uri){ |
| 699 |
entry.addAuthor(authors[i].name, authors[i].email, authors[i].uri); |
| 700 |
} |
| 701 |
} |
| 702 |
|
| 703 |
contributors = this._editors.contributors.getValues(); |
| 704 |
for(i in contributors){ |
| 705 |
if(contributors[i].name || contributors[i].email || contributors[i].uri){ |
| 706 |
entry.addContributor(contributors[i].name, contributors[i].email, contributors[i].uri); |
| 707 |
} |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
value = this._editors.summary.attr('value'); |
| 712 |
if(this.entrySummarySelect.value === "xhtml"){ |
| 713 |
value = this._enforceXhtml(value); |
| 714 |
value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>'; |
| 715 |
} |
| 716 |
entry.summary = new model.Content("summary", value, null, this.entrySummarySelect.value); |
| 717 |
|
| 718 |
value = this._editors.content.attr('value'); |
| 719 |
if(this.entryContentSelect.value === "xhtml"){ |
| 720 |
value = this._enforceXhtml(value); |
| 721 |
value = '<div xmlns="http://www.w3.org/1999/xhtml">' + value + '</div>'; |
| 722 |
} |
| 723 |
entry.content = new model.Content("content", value, null, this.entryContentSelect.value); |
| 724 |
|
| 725 |
domStyle.set(this.entryNewButton, 'display', ''); |
| 726 |
dojo.publish(this.entrySelectionTopic, [{action: "post", source: this, entry: entry }]); |
| 727 |
} |
| 728 |
this._editMode = false; |
| 729 |
|
| 730 |
|
| 731 |
this.setEntry(entry, this._feed, true); |
| 732 |
}, |
| 733 |
|
| 734 |
_handleSave: function(entry, location){ |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
this._editMode = false; |
| 745 |
|
| 746 |
|
| 747 |
this.clear(); |
| 748 |
this.setEntry(entry, this.getFeed(), true); |
| 749 |
}, |
| 750 |
|
| 751 |
cancelEdits: function(){ |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
this._new = false; |
| 757 |
domStyle.set(this.entrySaveCancelButtons, 'display', 'none'); |
| 758 |
if(this._editable){ |
| 759 |
domStyle.set(this.entryEditButton, 'display', ''); |
| 760 |
} |
| 761 |
domStyle.set(this.entryNewButton, 'display', ''); |
| 762 |
this._editMode = false; |
| 763 |
|
| 764 |
|
| 765 |
this.clearEditors(); |
| 766 |
this.setEntry(this.getEntry(), this.getFeed(), true); |
| 767 |
}, |
| 768 |
|
| 769 |
clear: function(){ |
| 770 |
|
| 771 |
|
| 772 |
this._editable=false; |
| 773 |
this.clearEditors(); |
| 774 |
FeedEntryEditor.superclass.clear.apply(this); |
| 775 |
if(this._contentEditor){ |
| 776 |
|
| 777 |
|
| 778 |
this._contentEditor = this._setObject = this._oldContent = this._contentEditorCreator = null; |
| 779 |
this._editors = {}; |
| 780 |
} |
| 781 |
}, |
| 782 |
|
| 783 |
clearEditors: function(){ |
| 784 |
for(var key in this._editors){ |
| 785 |
if(this._editors[key].isInstanceOf(Editor)){ |
| 786 |
this._editors[key].close(false, true); |
| 787 |
} |
| 788 |
this._editors[key].destroy(); |
| 789 |
} |
| 790 |
this._editors = {}; |
| 791 |
}, |
| 792 |
|
| 793 |
_enforceXhtml: function(html){ |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
var xhtml = null; |
| 801 |
if(html){ |
| 802 |
|
| 803 |
var brRegExp = /<br>/g; |
| 804 |
xhtml = html.replace(brRegExp, "<br/>"); |
| 805 |
|
| 806 |
|
| 807 |
xhtml = this._closeTag(xhtml, "hr"); |
| 808 |
|
| 809 |
|
| 810 |
xhtml = this._closeTag(xhtml, "img"); |
| 811 |
} |
| 812 |
return xhtml; |
| 813 |
}, |
| 814 |
|
| 815 |
_closeTag: function(xhtml, tag){ |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
var tagStart = "<" + tag; |
| 827 |
var tagIndex = xhtml.indexOf(tagStart); |
| 828 |
if(tagIndex !== -1){ |
| 829 |
while (tagIndex !== -1){ |
| 830 |
var tempString = ""; |
| 831 |
var foundTagEnd = false; |
| 832 |
for (var i = 0; i < xhtml.length; i++){ |
| 833 |
var c = xhtml.charAt(i); |
| 834 |
if(i <= tagIndex ||foundTagEnd){ |
| 835 |
tempString += c; |
| 836 |
} |
| 837 |
else |
| 838 |
{ |
| 839 |
if(c === '>'){ |
| 840 |
tempString += "/"; |
| 841 |
foundTagEnd = true; |
| 842 |
} |
| 843 |
tempString +=c; |
| 844 |
} |
| 845 |
} |
| 846 |
xhtml = tempString; |
| 847 |
tagIndex = xhtml.indexOf(tagStart, tagIndex + 1); |
| 848 |
} |
| 849 |
} |
| 850 |
return xhtml; |
| 851 |
}, |
| 852 |
|
| 853 |
_toggleNew: function(){ |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
domStyle.set(this.entryNewButton, 'display', 'none'); |
| 859 |
domStyle.set(this.entryEditButton, 'display', 'none'); |
| 860 |
domStyle.set(this.entrySaveCancelButtons, 'display', ''); |
| 861 |
|
| 862 |
|
| 863 |
this.entrySummarySelect.value = "text"; |
| 864 |
this.entryContentSelect.value = "text"; |
| 865 |
this.entryTitleSelect.value = "text"; |
| 866 |
|
| 867 |
|
| 868 |
this.clearNodes(); |
| 869 |
this._new = true; |
| 870 |
|
| 871 |
var _nlsResources = i18nViewer; |
| 872 |
|
| 873 |
var titleHeader = new FeedEntryViewer.EntryHeader({title: _nlsResources.title}); |
| 874 |
this.entryTitleHeader.appendChild(titleHeader.domNode); |
| 875 |
|
| 876 |
this._editors.title = this._createEditor(this.entryTitleNode, null); |
| 877 |
this.setFieldValidity("title",true); |
| 878 |
|
| 879 |
var authorHeader = new FeedEntryViewer.EntryHeader({title: _nlsResources.authors}); |
| 880 |
this.entryAuthorHeader.appendChild(authorHeader.domNode); |
| 881 |
|
| 882 |
this._editors.authors = this._createPeopleEditor(this.entryAuthorNode, {name: "Author"}); |
| 883 |
this.setFieldValidity("authors", true); |
| 884 |
|
| 885 |
var contributorHeader = new FeedEntryViewer.EntryHeader({title: _nlsResources.contributors}); |
| 886 |
this.entryContributorHeader.appendChild(contributorHeader.domNode); |
| 887 |
|
| 888 |
this._editors.contributors = this._createPeopleEditor(this.entryContributorNode, {name: "Contributor"}); |
| 889 |
this.setFieldValidity("contributors", true); |
| 890 |
|
| 891 |
var idHeader = new FeedEntryViewer.EntryHeader({title: _nlsResources.id}); |
| 892 |
this.entryIdHeader.appendChild(idHeader.domNode); |
| 893 |
|
| 894 |
this._editors.id = this._createEditor(this.entryIdNode, null); |
| 895 |
this.setFieldValidity("id",true); |
| 896 |
|
| 897 |
var updatedHeader = new FeedEntryViewer.EntryHeader({title: _nlsResources.updated}); |
| 898 |
this.entryUpdatedHeader.appendChild(updatedHeader.domNode); |
| 899 |
|
| 900 |
this._editors.updated = this._createEditor(this.entryUpdatedNode, null); |
| 901 |
this.setFieldValidity("updated",true); |
| 902 |
|
| 903 |
var summaryHeader = new FeedEntryViewer.EntryHeader({title: _nlsResources.summary}); |
| 904 |
this.entrySummaryHeader.appendChild(summaryHeader.domNode); |
| 905 |
|
| 906 |
this._editors.summary = this._createEditor(this.entrySummaryNode, null, true); |
| 907 |
this.setFieldValidity("summaryedit",true); |
| 908 |
this.setFieldValidity("summary",true); |
| 909 |
|
| 910 |
var contentHeader = new FeedEntryViewer.EntryHeader({title: _nlsResources.content}); |
| 911 |
this.entryContentHeader.appendChild(contentHeader.domNode); |
| 912 |
|
| 913 |
this._editors.content = this._createEditor(this.entryContentNode, null, true); |
| 914 |
this.setFieldValidity("contentedit",true); |
| 915 |
this.setFieldValidity("content",true); |
| 916 |
|
| 917 |
|
| 918 |
this._displaySections(); |
| 919 |
}, |
| 920 |
|
| 921 |
_displaySections: function(){ |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
domStyle.set(this.entrySummarySelect, 'display', 'none'); |
| 927 |
domStyle.set(this.entryContentSelect, 'display', 'none'); |
| 928 |
domStyle.set(this.entryTitleSelect, 'display', 'none'); |
| 929 |
|
| 930 |
|
| 931 |
if(this.isFieldValid("contentedit")){ |
| 932 |
domStyle.set(this.entryContentSelect, 'display', ''); |
| 933 |
} |
| 934 |
if(this.isFieldValid("summaryedit")){ |
| 935 |
domStyle.set(this.entrySummarySelect, 'display', ''); |
| 936 |
} |
| 937 |
if(this.isFieldValid("titleedit")){ |
| 938 |
domStyle.set(this.entryTitleSelect, 'display', ''); |
| 939 |
} |
| 940 |
|
| 941 |
FeedEntryEditor.superclass._displaySections.apply(this); |
| 942 |
|
| 943 |
|
| 944 |
if(this._toLoad){ |
| 945 |
for(var i in this._toLoad){ |
| 946 |
var editor; |
| 947 |
if(this._toLoad[i].generateEditor){ |
| 948 |
editor = lang.hitch(this._toLoad[i], this._toLoad[i].generateEditor)(); |
| 949 |
}else{ |
| 950 |
editor = this._toLoad[i]; |
| 951 |
} |
| 952 |
this._editors[this._toLoad[i].name] = editor; |
| 953 |
this._toLoad[i] = null; |
| 954 |
} |
| 955 |
this._toLoad = null; |
| 956 |
} |
| 957 |
} |
| 958 |
}); |
| 959 |
|
| 960 |
var PeopleEditor = declare("dojox.atom.widget.PeopleEditor", [_Widget, _Templated, _Container],{ |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
templateString: peopleEditorTemplate, |
| 967 |
|
| 968 |
_rows: [], |
| 969 |
_editors: [], |
| 970 |
_index: 0, |
| 971 |
_numRows: 0, |
| 972 |
|
| 973 |
postCreate: function(){ |
| 974 |
|
| 975 |
var _nlsResources = i18nPeople; |
| 976 |
if(this.name){ |
| 977 |
if(this.name == "Author"){ |
| 978 |
this.peopleEditorButton.appendChild(document.createTextNode("["+_nlsResources.addAuthor+"]")); |
| 979 |
}else if(this.name == "Contributor"){ |
| 980 |
this.peopleEditorButton.appendChild(document.createTextNode("["+_nlsResources.addContributor+"]")); |
| 981 |
} |
| 982 |
}else{ |
| 983 |
this.peopleEditorButton.appendChild(document.createTextNode("["+_nlsResources.add+"]")); |
| 984 |
} |
| 985 |
this._editors = []; |
| 986 |
|
| 987 |
if(!this.data || this.data.length===0){ |
| 988 |
this._createEditors(null, null, null, 0, this.name); |
| 989 |
this._index = 1; |
| 990 |
}else{ |
| 991 |
for(var i in this.data){ |
| 992 |
this._createEditors(this.data[i].name, this.data[i].email, this.data[i].uri, i); |
| 993 |
this._index++; |
| 994 |
this._numRows++; |
| 995 |
} |
| 996 |
} |
| 997 |
}, |
| 998 |
|
| 999 |
destroy: function(){ |
| 1000 |
for(var key in this._editors){ |
| 1001 |
for(var key2 in this._editors[key]){ |
| 1002 |
this._editors[key][key2].destroy(); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
this._editors = []; |
| 1006 |
}, |
| 1007 |
|
| 1008 |
_createEditors: function(name, email, uri, index, widgetName){ |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
var row = document.createElement("tr"); |
| 1020 |
this.peopleEditorEditors.appendChild(row); |
| 1021 |
row.id = "removeRow"+index; |
| 1022 |
|
| 1023 |
var node = document.createElement("td"); |
| 1024 |
node.setAttribute('align', 'right'); |
| 1025 |
row.appendChild(node); |
| 1026 |
node.colSpan = 2; |
| 1027 |
|
| 1028 |
if(this._numRows>0){ |
| 1029 |
var hr = document.createElement("hr"); |
| 1030 |
node.appendChild(hr); |
| 1031 |
hr.id = "hr"+index; |
| 1032 |
} |
| 1033 |
|
| 1034 |
row = document.createElement("span"); |
| 1035 |
node.appendChild(row); |
| 1036 |
row.className = "peopleEditorButton"; |
| 1037 |
domStyle.set(row, 'font-size', 'x-small'); |
| 1038 |
connect.connect(row, "onclick", this, "_removeEditor"); |
| 1039 |
row.id = "remove"+index; |
| 1040 |
|
| 1041 |
node = document.createTextNode("[X]"); |
| 1042 |
row.appendChild(node); |
| 1043 |
|
| 1044 |
row = document.createElement("tr"); |
| 1045 |
this.peopleEditorEditors.appendChild(row); |
| 1046 |
row.id = "editorsRow"+index; |
| 1047 |
|
| 1048 |
var labelNode = document.createElement("td"); |
| 1049 |
row.appendChild(labelNode); |
| 1050 |
domStyle.set(labelNode, 'width', '20%'); |
| 1051 |
|
| 1052 |
node = document.createElement("td"); |
| 1053 |
row.appendChild(node); |
| 1054 |
|
| 1055 |
row = document.createElement("table"); |
| 1056 |
labelNode.appendChild(row); |
| 1057 |
domStyle.set(row, 'width', '100%'); |
| 1058 |
|
| 1059 |
labelNode = document.createElement("tbody"); |
| 1060 |
row.appendChild(labelNode); |
| 1061 |
|
| 1062 |
row = document.createElement("table"); |
| 1063 |
node.appendChild(row); |
| 1064 |
domStyle.set(row, 'width', '100%'); |
| 1065 |
|
| 1066 |
node = document.createElement("tbody"); |
| 1067 |
row.appendChild(node); |
| 1068 |
|
| 1069 |
this._editors[index] = []; |
| 1070 |
this._editors[index].push(this._createEditor(name, widgetName+'name'+index, 'Name:', labelNode, node)); |
| 1071 |
this._editors[index].push(this._createEditor(email, widgetName+'email'+index, 'Email:', labelNode, node)); |
| 1072 |
this._editors[index].push(this._createEditor(uri, widgetName+'uri'+index, 'URI:', labelNode, node)); |
| 1073 |
}, |
| 1074 |
|
| 1075 |
_createEditor: function(value, id, name, labelNode, node){ |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
var row = document.createElement("tr"); |
| 1091 |
labelNode.appendChild(row); |
| 1092 |
|
| 1093 |
var label = document.createElement("label"); |
| 1094 |
label.setAttribute('for', id); |
| 1095 |
label.appendChild(document.createTextNode(name)); |
| 1096 |
labelNode = document.createElement("td"); |
| 1097 |
labelNode.appendChild(label); |
| 1098 |
row.appendChild(labelNode); |
| 1099 |
|
| 1100 |
row = document.createElement("tr"); |
| 1101 |
node.appendChild(row); |
| 1102 |
|
| 1103 |
node = document.createElement("td"); |
| 1104 |
row.appendChild(node); |
| 1105 |
|
| 1106 |
var viewNode = document.createElement("input"); |
| 1107 |
viewNode.setAttribute('id', id); |
| 1108 |
node.appendChild(viewNode); |
| 1109 |
domStyle.set(viewNode, 'width', '95%'); |
| 1110 |
|
| 1111 |
var box = new TextBox({},viewNode); |
| 1112 |
box.attr('value', value); |
| 1113 |
return box; |
| 1114 |
}, |
| 1115 |
|
| 1116 |
_removeEditor: function(event){ |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
var target = null; |
| 1125 |
|
| 1126 |
if(has("ie")){ |
| 1127 |
target = event.srcElement; |
| 1128 |
}else{ |
| 1129 |
target = event.target; |
| 1130 |
} |
| 1131 |
|
| 1132 |
var id = target.id; |
| 1133 |
id = id.substring(6); |
| 1134 |
for(var key in this._editors[id]){ |
| 1135 |
this._editors[id][key].destroy(); |
| 1136 |
} |
| 1137 |
|
| 1138 |
var node = domUtil.byId("editorsRow"+id); |
| 1139 |
var parent = node.parentNode; |
| 1140 |
parent.removeChild(node); |
| 1141 |
|
| 1142 |
node = domUtil.byId("removeRow"+id); |
| 1143 |
parent = node.parentNode; |
| 1144 |
parent.removeChild(node); |
| 1145 |
|
| 1146 |
this._numRows--; |
| 1147 |
if(this._numRows === 1 && parent.firstChild.firstChild.firstChild.tagName.toLowerCase() === "hr"){ |
| 1148 |
node = parent.firstChild.firstChild; |
| 1149 |
node.removeChild(node.firstChild); |
| 1150 |
} |
| 1151 |
this._editors[id] = null; |
| 1152 |
}, |
| 1153 |
|
| 1154 |
_add: function(){ |
| 1155 |
|
| 1156 |
|
| 1157 |
this._createEditors(null, null, null, this._index); |
| 1158 |
this._index++; |
| 1159 |
this._numRows++; |
| 1160 |
}, |
| 1161 |
|
| 1162 |
getValues: function(){ |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
var values = []; |
| 1170 |
for(var i in this._editors){ |
| 1171 |
if(this._editors[i]){ |
| 1172 |
values.push({name: this._editors[i][0].attr('value'), email: this._editors[i][1].attr('value'), uri: this._editors[i][2].attr('value')}); |
| 1173 |
} |
| 1174 |
} |
| 1175 |
return values; |
| 1176 |
} |
| 1177 |
}); |
| 1178 |
|
| 1179 |
return FeedEntryEditor; |
| 1180 |
}); |