| 1 |
define(["dojo", "dojox", "dojo/data/util/simpleFetch", "dojo/data/util/filter", "dojox/atom/io/Connection"], function(dojo, dojox) { |
| 2 |
|
| 3 |
dojo.experimental("dojox.data.AppStore"); |
| 4 |
|
| 5 |
var AppStore = dojo.declare("dojox.data.AppStore", null, { |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
url: "", |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
urlPreventCache: false, |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
xmethod: false, |
| 18 |
|
| 19 |
_atomIO: null, |
| 20 |
_feed: null, |
| 21 |
_requests: null, |
| 22 |
_processing: null, |
| 23 |
|
| 24 |
_updates: null, |
| 25 |
_adds: null, |
| 26 |
_deletes: null, |
| 27 |
|
| 28 |
constructor: function(args){ |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
if(args && args.url){ |
| 41 |
this.url = args.url; |
| 42 |
} |
| 43 |
if(args && args.urlPreventCache){ |
| 44 |
this.urlPreventCache = args.urlPreventCache; |
| 45 |
} |
| 46 |
if(!this.url){ |
| 47 |
throw new Error("A URL is required to instantiate an APP Store object"); |
| 48 |
} |
| 49 |
}, |
| 50 |
|
| 51 |
_setFeed: function(feed, data){ |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
this._feed = feed; |
| 64 |
var i; |
| 65 |
for(i=0; i<this._feed.entries.length; i++){ |
| 66 |
this._feed.entries[i].store = this; |
| 67 |
} |
| 68 |
if(this._requests){ |
| 69 |
for(i=0; i<this._requests.length; i++){ |
| 70 |
var request = this._requests[i]; |
| 71 |
if(request.request && request.fh && request.eh){ |
| 72 |
this._finishFetchItems(request.request, request.fh, request.eh); |
| 73 |
}else if(request.clear){ |
| 74 |
this._feed = null; |
| 75 |
}else if(request.add){ |
| 76 |
this._feed.addEntry(request.add); |
| 77 |
}else if(request.remove){ |
| 78 |
this._feed.removeEntry(request.remove); |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
this._requests = null; |
| 83 |
}, |
| 84 |
|
| 85 |
_getAllItems: function(){ |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
var items = []; |
| 93 |
for(var i=0; i<this._feed.entries.length; i++){ |
| 94 |
items.push(this._feed.entries[i]); |
| 95 |
} |
| 96 |
return items; |
| 97 |
}, |
| 98 |
|
| 99 |
_assertIsItem: function( item){ |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
if(!this.isItem(item)){ |
| 108 |
throw new Error("This error message is provided when a function is called in the following form: " |
| 109 |
+ "getAttribute(argument, attributeName). The argument variable represents the member " |
| 110 |
+ "or owner of the object. The error is created when an item that does not belong " |
| 111 |
+ "to this store is specified as an argument."); |
| 112 |
} |
| 113 |
}, |
| 114 |
|
| 115 |
_assertIsAttribute: function( attribute){ |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
if(typeof attribute !== "string"){ |
| 126 |
throw new Error("The attribute argument must be a string. The error is created " |
| 127 |
+ "when a different type of variable is specified such as an array or object."); |
| 128 |
} |
| 129 |
|
| 130 |
for(var key in dojox.atom.io.model._actions){ |
| 131 |
if(key == attribute){ |
| 132 |
return true; |
| 133 |
} |
| 134 |
} |
| 135 |
return false; |
| 136 |
}, |
| 137 |
|
| 138 |
_addUpdate: function( update){ |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
if(!this._updates){ |
| 146 |
this._updates = [update]; |
| 147 |
}else{ |
| 148 |
this._updates.push(update); |
| 149 |
} |
| 150 |
}, |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
getValue: function( item, |
| 157 |
attribute, |
| 158 |
defaultValue){ |
| 159 |
|
| 160 |
|
| 161 |
var values = this.getValues(item, attribute); |
| 162 |
return (values.length > 0)?values[0]:defaultValue; |
| 163 |
}, |
| 164 |
|
| 165 |
getValues: function( item, |
| 166 |
attribute){ |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
this._assertIsItem(item); |
| 171 |
var flag = this._assertIsAttribute(attribute); |
| 172 |
|
| 173 |
if(flag){ |
| 174 |
if((attribute === "author" || attribute === "contributor" || attribute === "link") && item[attribute+"s"]){ |
| 175 |
return item[attribute+"s"]; |
| 176 |
} |
| 177 |
if(attribute === "category" && item.categories){ |
| 178 |
return item.categories; |
| 179 |
} |
| 180 |
if(item[attribute]){ |
| 181 |
item = item[attribute]; |
| 182 |
if(item.nodeType == "Content"){ |
| 183 |
return [item.value]; |
| 184 |
} |
| 185 |
return [item] ; |
| 186 |
} |
| 187 |
} |
| 188 |
return []; |
| 189 |
}, |
| 190 |
|
| 191 |
getAttributes: function( item){ |
| 192 |
|
| 193 |
|
| 194 |
this._assertIsItem(item); |
| 195 |
var attributes = []; |
| 196 |
for(var key in dojox.atom.io.model._actions){ |
| 197 |
if(this.hasAttribute(item, key)){ |
| 198 |
attributes.push(key); |
| 199 |
} |
| 200 |
} |
| 201 |
return attributes; |
| 202 |
}, |
| 203 |
|
| 204 |
hasAttribute: function( item, |
| 205 |
attribute){ |
| 206 |
|
| 207 |
|
| 208 |
return this.getValues(item, attribute).length > 0; |
| 209 |
}, |
| 210 |
|
| 211 |
containsValue: function( item, |
| 212 |
attribute, |
| 213 |
value){ |
| 214 |
|
| 215 |
|
| 216 |
var regexp = undefined; |
| 217 |
if(typeof value === "string"){ |
| 218 |
regexp = dojo.data.util.filter.patternToRegExp(value, false); |
| 219 |
} |
| 220 |
return this._containsValue(item, attribute, value, regexp); |
| 221 |
}, |
| 222 |
|
| 223 |
_containsValue: function( item, |
| 224 |
attribute, |
| 225 |
value, |
| 226 |
regexp, |
| 227 |
trim){ |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
var values = this.getValues(item, attribute); |
| 244 |
for(var i = 0; i < values.length; ++i){ |
| 245 |
var possibleValue = values[i]; |
| 246 |
if(typeof possibleValue === "string" && regexp){ |
| 247 |
if(trim){ |
| 248 |
possibleValue = possibleValue.replace(new RegExp(/^\s+/),""); |
| 249 |
possibleValue = possibleValue.replace(new RegExp(/\s+$/),""); |
| 250 |
} |
| 251 |
possibleValue = possibleValue.replace(/\r|\n|\r\n/g, ""); |
| 252 |
return (possibleValue.match(regexp) !== null); |
| 253 |
}else{ |
| 254 |
|
| 255 |
if(value === possibleValue){ |
| 256 |
return true; |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
return false; |
| 261 |
}, |
| 262 |
|
| 263 |
isItem: function( something){ |
| 264 |
|
| 265 |
|
| 266 |
return something && something.store && something.store === this; |
| 267 |
}, |
| 268 |
|
| 269 |
isItemLoaded: function( something){ |
| 270 |
|
| 271 |
|
| 272 |
return this.isItem(something); |
| 273 |
}, |
| 274 |
|
| 275 |
loadItem: function( keywordArgs){ |
| 276 |
|
| 277 |
|
| 278 |
this._assertIsItem(keywordArgs.item); |
| 279 |
}, |
| 280 |
|
| 281 |
_fetchItems: function(request, fetchHandler, errorHandler){ |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
if(this._feed){ |
| 293 |
this._finishFetchItems(request, fetchHandler, errorHandler); |
| 294 |
}else{ |
| 295 |
var flag = false; |
| 296 |
if(!this._requests){ |
| 297 |
this._requests = []; |
| 298 |
flag = true; |
| 299 |
} |
| 300 |
this._requests.push({request: request, fh: fetchHandler, eh: errorHandler}); |
| 301 |
if(flag){ |
| 302 |
this._atomIO = new dojox.atom.io.Connection(false, this.urlPreventCache); |
| 303 |
this._atomIO.getFeed(this.url,this._setFeed, null, this); |
| 304 |
} |
| 305 |
} |
| 306 |
}, |
| 307 |
|
| 308 |
_finishFetchItems: function(request, fetchHandler, errorHandler){ |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
var items = null; |
| 321 |
var arrayOfAllItems = this._getAllItems(); |
| 322 |
if(request.query){ |
| 323 |
var ignoreCase = request.queryOptions ? request.queryOptions.ignoreCase : false; |
| 324 |
items = []; |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
var regexpList = {}; |
| 329 |
var key; |
| 330 |
var value; |
| 331 |
for(key in request.query){ |
| 332 |
value = request.query[key]+''; |
| 333 |
if(typeof value === "string"){ |
| 334 |
regexpList[key] = dojo.data.util.filter.patternToRegExp(value, ignoreCase); |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
for(var i = 0; i < arrayOfAllItems.length; ++i){ |
| 339 |
var match = true; |
| 340 |
var candidateItem = arrayOfAllItems[i]; |
| 341 |
for(key in request.query){ |
| 342 |
value = request.query[key]+''; |
| 343 |
if(!this._containsValue(candidateItem, key, value, regexpList[key], request.trim)){ |
| 344 |
match = false; |
| 345 |
} |
| 346 |
} |
| 347 |
if(match){ |
| 348 |
items.push(candidateItem); |
| 349 |
} |
| 350 |
} |
| 351 |
}else{ |
| 352 |
|
| 353 |
|
| 354 |
if(arrayOfAllItems.length> 0){ |
| 355 |
items = arrayOfAllItems.slice(0,arrayOfAllItems.length); |
| 356 |
} |
| 357 |
} |
| 358 |
try{ |
| 359 |
fetchHandler(items, request); |
| 360 |
}catch(e){ |
| 361 |
errorHandler(e, request); |
| 362 |
} |
| 363 |
}, |
| 364 |
|
| 365 |
getFeatures: function(){ |
| 366 |
|
| 367 |
|
| 368 |
return { |
| 369 |
'dojo.data.api.Read': true, |
| 370 |
'dojo.data.api.Write': true, |
| 371 |
'dojo.data.api.Identity': true |
| 372 |
}; |
| 373 |
}, |
| 374 |
|
| 375 |
close: function( request){ |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
this._feed = null; |
| 381 |
}, |
| 382 |
|
| 383 |
getLabel: function( item){ |
| 384 |
|
| 385 |
|
| 386 |
if(this.isItem(item)){ |
| 387 |
return this.getValue(item, "title", "No Title"); |
| 388 |
} |
| 389 |
return undefined; |
| 390 |
}, |
| 391 |
|
| 392 |
getLabelAttributes: function( item){ |
| 393 |
|
| 394 |
|
| 395 |
return ["title"]; |
| 396 |
}, |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
getIdentity: function( item){ |
| 403 |
|
| 404 |
|
| 405 |
this._assertIsItem(item); |
| 406 |
return this.getValue(item, "id"); |
| 407 |
}, |
| 408 |
|
| 409 |
getIdentityAttributes: function( item){ |
| 410 |
|
| 411 |
|
| 412 |
return ["id"]; |
| 413 |
}, |
| 414 |
|
| 415 |
fetchItemByIdentity: function(keywordArgs){ |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
this._fetchItems({query:{id:keywordArgs.identity}, onItem: keywordArgs.onItem, scope: keywordArgs.scope}, |
| 420 |
function(items, request){ |
| 421 |
var scope = request.scope; |
| 422 |
if(!scope){ |
| 423 |
scope = dojo.global; |
| 424 |
} |
| 425 |
if(items.length < 1){ |
| 426 |
request.onItem.call(scope, null); |
| 427 |
}else{ |
| 428 |
request.onItem.call(scope, items[0]); |
| 429 |
} |
| 430 |
}, keywordArgs.onError); |
| 431 |
}, |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
newItem: function( keywordArgs){ |
| 438 |
|
| 439 |
|
| 440 |
var entry = new dojox.atom.io.model.Entry(); |
| 441 |
var value = null; |
| 442 |
var temp = null; |
| 443 |
var i; |
| 444 |
for(var key in keywordArgs){ |
| 445 |
if(this._assertIsAttribute(key)){ |
| 446 |
value = keywordArgs[key]; |
| 447 |
switch(key){ |
| 448 |
case "link": |
| 449 |
for(i in value){ |
| 450 |
temp = value[i]; |
| 451 |
entry.addLink(temp.href,temp.rel,temp.hrefLang,temp.title,temp.type); |
| 452 |
} |
| 453 |
break; |
| 454 |
case "author": |
| 455 |
for(i in value){ |
| 456 |
temp = value[i]; |
| 457 |
entry.addAuthor(temp.name, temp.email, temp.uri); |
| 458 |
} |
| 459 |
break; |
| 460 |
case "contributor": |
| 461 |
for(i in value){ |
| 462 |
temp = value[i]; |
| 463 |
entry.addContributor(temp.name, temp.email, temp.uri); |
| 464 |
} |
| 465 |
break; |
| 466 |
case "category": |
| 467 |
for(i in value){ |
| 468 |
temp = value[i]; |
| 469 |
entry.addCategory(temp.scheme, temp.term, temp.label); |
| 470 |
} |
| 471 |
break; |
| 472 |
case "icon": |
| 473 |
case "id": |
| 474 |
case "logo": |
| 475 |
case "xmlBase": |
| 476 |
case "rights": |
| 477 |
entry[key] = value; |
| 478 |
break; |
| 479 |
case "updated": |
| 480 |
case "published": |
| 481 |
case "issued": |
| 482 |
case "modified": |
| 483 |
entry[key] = dojox.atom.io.model.util.createDate(value); |
| 484 |
break; |
| 485 |
case "content": |
| 486 |
case "summary": |
| 487 |
case "title": |
| 488 |
case "subtitle": |
| 489 |
entry[key] = new dojox.atom.io.model.Content(key); |
| 490 |
entry[key].value = value; |
| 491 |
break; |
| 492 |
default: |
| 493 |
entry[key] = value; |
| 494 |
break; |
| 495 |
} |
| 496 |
} |
| 497 |
} |
| 498 |
entry.store = this; |
| 499 |
entry.isDirty = true; |
| 500 |
|
| 501 |
if(!this._adds){ |
| 502 |
this._adds = [entry]; |
| 503 |
}else{ |
| 504 |
this._adds.push(entry); |
| 505 |
} |
| 506 |
|
| 507 |
if(this._feed){ |
| 508 |
this._feed.addEntry(entry); |
| 509 |
}else{ |
| 510 |
if(this._requests){ |
| 511 |
this._requests.push({add:entry}); |
| 512 |
}else{ |
| 513 |
this._requests = [{add:entry}]; |
| 514 |
this._atomIO = new dojox.atom.io.Connection(false, this.urlPreventCache); |
| 515 |
this._atomIO.getFeed(this.url,dojo.hitch(this,this._setFeed)); |
| 516 |
} |
| 517 |
} |
| 518 |
return true; |
| 519 |
}, |
| 520 |
|
| 521 |
deleteItem: function( item){ |
| 522 |
|
| 523 |
|
| 524 |
this._assertIsItem(item); |
| 525 |
|
| 526 |
if(!this._deletes){ |
| 527 |
this._deletes = [item]; |
| 528 |
}else{ |
| 529 |
this._deletes.push(item); |
| 530 |
} |
| 531 |
|
| 532 |
if(this._feed){ |
| 533 |
this._feed.removeEntry(item); |
| 534 |
}else{ |
| 535 |
if(this._requests){ |
| 536 |
this._requests.push({remove:item}); |
| 537 |
}else{ |
| 538 |
this._requests = [{remove:item}]; |
| 539 |
this._atomIO = new dojox.atom.io.Connection(false, this.urlPreventCache); |
| 540 |
this._atomIO.getFeed(this.url,dojo.hitch(this,this._setFeed)); |
| 541 |
} |
| 542 |
} |
| 543 |
item = null; |
| 544 |
return true; |
| 545 |
}, |
| 546 |
|
| 547 |
setValue: function( item, |
| 548 |
attribute, |
| 549 |
value){ |
| 550 |
|
| 551 |
|
| 552 |
this._assertIsItem(item); |
| 553 |
|
| 554 |
var update = {item: item}; |
| 555 |
if(this._assertIsAttribute(attribute)){ |
| 556 |
switch(attribute){ |
| 557 |
case "link": |
| 558 |
update.links = item.links; |
| 559 |
this._addUpdate(update); |
| 560 |
item.links = null; |
| 561 |
item.addLink(value.href,value.rel,value.hrefLang,value.title,value.type); |
| 562 |
item.isDirty = true; |
| 563 |
return true; |
| 564 |
case "author": |
| 565 |
update.authors = item.authors; |
| 566 |
this._addUpdate(update); |
| 567 |
item.authors = null; |
| 568 |
item.addAuthor(value.name, value.email, value.uri); |
| 569 |
item.isDirty = true; |
| 570 |
return true; |
| 571 |
case "contributor": |
| 572 |
update.contributors = item.contributors; |
| 573 |
this._addUpdate(update); |
| 574 |
item.contributors = null; |
| 575 |
item.addContributor(value.name, value.email, value.uri); |
| 576 |
item.isDirty = true; |
| 577 |
return true; |
| 578 |
case "category": |
| 579 |
update.categories = item.categories; |
| 580 |
this._addUpdate(update); |
| 581 |
item.categories = null; |
| 582 |
item.addCategory(value.scheme, value.term, value.label); |
| 583 |
item.isDirty = true; |
| 584 |
return true; |
| 585 |
case "icon": |
| 586 |
case "id": |
| 587 |
case "logo": |
| 588 |
case "xmlBase": |
| 589 |
case "rights": |
| 590 |
update[attribute] = item[attribute]; |
| 591 |
this._addUpdate(update); |
| 592 |
item[attribute] = value; |
| 593 |
item.isDirty = true; |
| 594 |
return true; |
| 595 |
case "updated": |
| 596 |
case "published": |
| 597 |
case "issued": |
| 598 |
case "modified": |
| 599 |
update[attribute] = item[attribute]; |
| 600 |
this._addUpdate(update); |
| 601 |
item[attribute] = dojox.atom.io.model.util.createDate(value); |
| 602 |
item.isDirty = true; |
| 603 |
return true; |
| 604 |
case "content": |
| 605 |
case "summary": |
| 606 |
case "title": |
| 607 |
case "subtitle": |
| 608 |
update[attribute] = item[attribute]; |
| 609 |
this._addUpdate(update); |
| 610 |
item[attribute] = new dojox.atom.io.model.Content(attribute); |
| 611 |
item[attribute].value = value; |
| 612 |
item.isDirty = true; |
| 613 |
return true; |
| 614 |
default: |
| 615 |
update[attribute] = item[attribute]; |
| 616 |
this._addUpdate(update); |
| 617 |
item[attribute] = value; |
| 618 |
item.isDirty = true; |
| 619 |
return true; |
| 620 |
} |
| 621 |
} |
| 622 |
return false; |
| 623 |
}, |
| 624 |
|
| 625 |
setValues: function( item, |
| 626 |
attribute, |
| 627 |
values){ |
| 628 |
|
| 629 |
|
| 630 |
if(values.length === 0){ |
| 631 |
return this.unsetAttribute(item, attribute); |
| 632 |
} |
| 633 |
this._assertIsItem(item); |
| 634 |
|
| 635 |
var update = {item: item}; |
| 636 |
var value; |
| 637 |
var i; |
| 638 |
if(this._assertIsAttribute(attribute)){ |
| 639 |
switch(attribute){ |
| 640 |
case "link": |
| 641 |
update.links = item.links; |
| 642 |
item.links = null; |
| 643 |
for(i in values){ |
| 644 |
value = values[i]; |
| 645 |
item.addLink(value.href,value.rel,value.hrefLang,value.title,value.type); |
| 646 |
} |
| 647 |
item.isDirty = true; |
| 648 |
return true; |
| 649 |
case "author": |
| 650 |
update.authors = item.authors; |
| 651 |
item.authors = null; |
| 652 |
for(i in values){ |
| 653 |
value = values[i]; |
| 654 |
item.addAuthor(value.name, value.email, value.uri); |
| 655 |
} |
| 656 |
item.isDirty = true; |
| 657 |
return true; |
| 658 |
case "contributor": |
| 659 |
update.contributors = item.contributors; |
| 660 |
item.contributors = null; |
| 661 |
for(i in values){ |
| 662 |
value = values[i]; |
| 663 |
item.addContributor(value.name, value.email, value.uri); |
| 664 |
} |
| 665 |
item.isDirty = true; |
| 666 |
return true; |
| 667 |
case "categories": |
| 668 |
update.categories = item.categories; |
| 669 |
item.categories = null; |
| 670 |
for(i in values){ |
| 671 |
value = values[i]; |
| 672 |
item.addCategory(value.scheme, value.term, value.label); |
| 673 |
} |
| 674 |
item.isDirty = true; |
| 675 |
return true; |
| 676 |
case "icon": |
| 677 |
case "id": |
| 678 |
case "logo": |
| 679 |
case "xmlBase": |
| 680 |
case "rights": |
| 681 |
update[attribute] = item[attribute]; |
| 682 |
item[attribute] = values[0]; |
| 683 |
item.isDirty = true; |
| 684 |
return true; |
| 685 |
case "updated": |
| 686 |
case "published": |
| 687 |
case "issued": |
| 688 |
case "modified": |
| 689 |
update[attribute] = item[attribute]; |
| 690 |
item[attribute] = dojox.atom.io.model.util.createDate(values[0]); |
| 691 |
item.isDirty = true; |
| 692 |
return true; |
| 693 |
case "content": |
| 694 |
case "summary": |
| 695 |
case "title": |
| 696 |
case "subtitle": |
| 697 |
update[attribute] = item[attribute]; |
| 698 |
item[attribute] = new dojox.atom.io.model.Content(attribute); |
| 699 |
item[attribute].values[0] = values[0]; |
| 700 |
item.isDirty = true; |
| 701 |
return true; |
| 702 |
default: |
| 703 |
update[attribute] = item[attribute]; |
| 704 |
item[attribute] = values[0]; |
| 705 |
item.isDirty = true; |
| 706 |
return true; |
| 707 |
} |
| 708 |
} |
| 709 |
this._addUpdate(update); |
| 710 |
return false; |
| 711 |
}, |
| 712 |
|
| 713 |
unsetAttribute: function( item, |
| 714 |
attribute){ |
| 715 |
|
| 716 |
|
| 717 |
this._assertIsItem(item); |
| 718 |
if(this._assertIsAttribute(attribute)){ |
| 719 |
if(item[attribute] !== null){ |
| 720 |
var update = {item: item}; |
| 721 |
switch(attribute){ |
| 722 |
case "author": |
| 723 |
case "contributor": |
| 724 |
case "link": |
| 725 |
update[attribute+"s"] = item[attribute+"s"]; |
| 726 |
break; |
| 727 |
case "category": |
| 728 |
update.categories = item.categories; |
| 729 |
break; |
| 730 |
default: |
| 731 |
update[attribute] = item[attribute]; |
| 732 |
break; |
| 733 |
} |
| 734 |
item.isDirty = true; |
| 735 |
item[attribute] = null; |
| 736 |
this._addUpdate(update); |
| 737 |
return true; |
| 738 |
} |
| 739 |
} |
| 740 |
return false; |
| 741 |
}, |
| 742 |
|
| 743 |
save: function( keywordArgs){ |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
var i; |
| 753 |
for(i in this._adds){ |
| 754 |
this._atomIO.addEntry(this._adds[i], null, function(){}, keywordArgs.onError, false, keywordArgs.scope); |
| 755 |
} |
| 756 |
|
| 757 |
this._adds = null; |
| 758 |
|
| 759 |
for(i in this._updates){ |
| 760 |
this._atomIO.updateEntry(this._updates[i].item, function(){}, keywordArgs.onError, false, this.xmethod, keywordArgs.scope); |
| 761 |
} |
| 762 |
|
| 763 |
this._updates = null; |
| 764 |
|
| 765 |
for(i in this._deletes){ |
| 766 |
this._atomIO.removeEntry(this._deletes[i], function(){}, keywordArgs.onError, this.xmethod, keywordArgs.scope); |
| 767 |
} |
| 768 |
|
| 769 |
this._deletes = null; |
| 770 |
|
| 771 |
this._atomIO.getFeed(this.url,dojo.hitch(this,this._setFeed)); |
| 772 |
|
| 773 |
if(keywordArgs.onComplete){ |
| 774 |
var scope = keywordArgs.scope || dojo.global; |
| 775 |
keywordArgs.onComplete.call(scope); |
| 776 |
} |
| 777 |
}, |
| 778 |
|
| 779 |
revert: function(){ |
| 780 |
|
| 781 |
|
| 782 |
var i; |
| 783 |
for(i in this._adds){ |
| 784 |
this._feed.removeEntry(this._adds[i]); |
| 785 |
} |
| 786 |
|
| 787 |
this._adds = null; |
| 788 |
|
| 789 |
var update, item, key; |
| 790 |
for(i in this._updates){ |
| 791 |
update = this._updates[i]; |
| 792 |
item = update.item; |
| 793 |
for(key in update){ |
| 794 |
if(key !== "item"){ |
| 795 |
item[key] = update[key]; |
| 796 |
} |
| 797 |
} |
| 798 |
} |
| 799 |
this._updates = null; |
| 800 |
|
| 801 |
for(i in this._deletes){ |
| 802 |
this._feed.addEntry(this._deletes[i]); |
| 803 |
} |
| 804 |
this._deletes = null; |
| 805 |
return true; |
| 806 |
}, |
| 807 |
|
| 808 |
isDirty: function( item){ |
| 809 |
|
| 810 |
|
| 811 |
if(item){ |
| 812 |
this._assertIsItem(item); |
| 813 |
return item.isDirty?true:false; |
| 814 |
} |
| 815 |
return (this._adds !== null || this._updates !== null); |
| 816 |
} |
| 817 |
}); |
| 818 |
|
| 819 |
dojo.extend(AppStore, dojo.data.util.simpleFetch); |
| 820 |
|
| 821 |
return AppStore; |
| 822 |
}); |