author | Michael Krelin <hacker@klever.net> | 2006-10-01 20:31:31 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-10-01 20:31:31 (UTC) |
commit | d9372f72e080857d52ef7e60b99d95b3b3cb6ad3 (patch) (unidiff) | |
tree | b54d61a4c39c6182da8a5c76e0e9b8c44958903e /content | |
parent | fa83ec27570f4d397aefeaa11e1f74b49b8d9402 (diff) | |
download | fireflix-d9372f72e080857d52ef7e60b99d95b3b3cb6ad3.zip fireflix-d9372f72e080857d52ef7e60b99d95b3b3cb6ad3.tar.gz fireflix-d9372f72e080857d52ef7e60b99d95b3b3cb6ad3.tar.bz2 |
scroll newly obtained search results to the top
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@174 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | content/fireflix.js | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index 6681303..0f01d26 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -367,537 +367,538 @@ var fireflix = { | |||
367 | state: 'pending' | 367 | state: 'pending' |
368 | } ); | 368 | } ); |
369 | this.rowCount = this.files.length; | 369 | this.rowCount = this.files.length; |
370 | this.tree.rowCountChanged(this.rowCount-1,1); | 370 | this.tree.rowCountChanged(this.rowCount-1,1); |
371 | }, | 371 | }, |
372 | 372 | ||
373 | upload_worker: function() { | 373 | upload_worker: function() { |
374 | for(var f in this.files) { | 374 | for(var f in this.files) { |
375 | if(this.files[f].state=='pending') { | 375 | if(this.files[f].state=='pending') { |
376 | var ff = this.files[f]; | 376 | var ff = this.files[f]; |
377 | dump('upload '+ff.file+'\n'); | 377 | dump('upload '+ff.file+'\n'); |
378 | this.on_file_upload(ff); | 378 | this.on_file_upload(ff); |
379 | ff.state='uploading'; | 379 | ff.state='uploading'; |
380 | this.tree.invalidate(); | 380 | this.tree.invalidate(); |
381 | var _this = this; | 381 | var _this = this; |
382 | this.fireflix.flickr.upload_file( | 382 | this.fireflix.flickr.upload_file( |
383 | ff.file, { title: ff.title, tags: ff.tags }, | 383 | ff.file, { title: ff.title, tags: ff.tags }, |
384 | function(x,p) { | 384 | function(x,p) { |
385 | ff.photoid = p; | 385 | ff.photoid = p; |
386 | _this.batch_ids.push(p); | 386 | _this.batch_ids.push(p); |
387 | ff.state='completed'; | 387 | ff.state='completed'; |
388 | _this.tree.invalidate(); | 388 | _this.tree.invalidate(); |
389 | window.setTimeout(_this.upload_to,0,_this); | 389 | window.setTimeout(_this.upload_to,0,_this); |
390 | }, function(x,s,c,m) { | 390 | }, function(x,s,c,m) { |
391 | ff.state='failed'; | 391 | ff.state='failed'; |
392 | ff.flickr_errcode = c; | 392 | ff.flickr_errcode = c; |
393 | ff.flickr_errmsg = m; | 393 | ff.flickr_errmsg = m; |
394 | _this.tree.invalidate(); | 394 | _this.tree.invalidate(); |
395 | window.setTimeout(_this.upload_to,0,_this); | 395 | window.setTimeout(_this.upload_to,0,_this); |
396 | } | 396 | } |
397 | ); | 397 | ); |
398 | return; | 398 | return; |
399 | } | 399 | } |
400 | } | 400 | } |
401 | dump('uploading done\n'); | 401 | dump('uploading done\n'); |
402 | this.on_finish_upload(); | 402 | this.on_finish_upload(); |
403 | }, | 403 | }, |
404 | upload_to: function(_this) { _this.upload_worker(); }, | 404 | upload_to: function(_this) { _this.upload_worker(); }, |
405 | on_file_upload: function(f) { | 405 | on_file_upload: function(f) { |
406 | this.cmd_uploads_upload.setAttribute('disabled','true'); | 406 | this.cmd_uploads_upload.setAttribute('disabled','true'); |
407 | for(var fi in this.files) { | 407 | for(var fi in this.files) { |
408 | if(this.files[fi].file==f.file) { | 408 | if(this.files[fi].file==f.file) { |
409 | this.tree.ensureRowIsVisible(fi); | 409 | this.tree.ensureRowIsVisible(fi); |
410 | this.selection.rangedSelect(fi,fi,false); | 410 | this.selection.rangedSelect(fi,fi,false); |
411 | this.selection.currentIndex = fi; | 411 | this.selection.currentIndex = fi; |
412 | this.selToProps(); | 412 | this.selToProps(); |
413 | break; | 413 | break; |
414 | } | 414 | } |
415 | } | 415 | } |
416 | }, | 416 | }, |
417 | on_finish_upload: function() { | 417 | on_finish_upload: function() { |
418 | if(this.batch_ids.length) { | 418 | if(this.batch_ids.length) { |
419 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); | 419 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); |
420 | if(psn!=null) { | 420 | if(psn!=null) { |
421 | var pids = this.batch_ids.join(','); | 421 | var pids = this.batch_ids.join(','); |
422 | var ppid = this.batch_ids[0]; | 422 | var ppid = this.batch_ids[0]; |
423 | var _this = this; | 423 | var _this = this; |
424 | this.fireflix.flickr.api_call( | 424 | this.fireflix.flickr.api_call( |
425 | { | 425 | { |
426 | method: 'flickr.photosets.create', | 426 | method: 'flickr.photosets.create', |
427 | auth_token: 'default', | 427 | auth_token: 'default', |
428 | title: psn, | 428 | title: psn, |
429 | primary_photo_id: ppid | 429 | primary_photo_id: ppid |
430 | }, function(x) { | 430 | }, function(x) { |
431 | var npid = | 431 | var npid = |
432 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); | 432 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); |
433 | _this.fireflix.flickr.api_call( | 433 | _this.fireflix.flickr.api_call( |
434 | { | 434 | { |
435 | method: 'flickr.photosets.editPhotos', | 435 | method: 'flickr.photosets.editPhotos', |
436 | auth_token: 'default', | 436 | auth_token: 'default', |
437 | photoset_id: npid, | 437 | photoset_id: npid, |
438 | primary_photo_id: ppid, | 438 | primary_photo_id: ppid, |
439 | photo_ids: pids | 439 | photo_ids: pids |
440 | }, function(x) { | 440 | }, function(x) { |
441 | _this.fireflix.refresh_sets(); | 441 | _this.fireflix.refresh_sets(); |
442 | }, function(x,s,c,m) { | 442 | }, function(x,s,c,m) { |
443 | _this.fireflix.flickr_failure(x,s,c,m); | 443 | _this.fireflix.flickr_failure(x,s,c,m); |
444 | } | 444 | } |
445 | ); | 445 | ); |
446 | }, function(x,s,c,m) { | 446 | }, function(x,s,c,m) { |
447 | _this.fireflix.flickr_failure(x,s,c,m); | 447 | _this.fireflix.flickr_failure(x,s,c,m); |
448 | } | 448 | } |
449 | ); | 449 | ); |
450 | } | 450 | } |
451 | } | 451 | } |
452 | this.selection.clearSelection(); | 452 | this.selection.clearSelection(); |
453 | this.cmd_uploads_upload.setAttribute('disabled','false'); | 453 | this.cmd_uploads_upload.setAttribute('disabled','false'); |
454 | this.upload_progress.setAttribute('hidden','true'); | 454 | this.upload_progress.setAttribute('hidden','true'); |
455 | }, | 455 | }, |
456 | 456 | ||
457 | clear_list: function() { | 457 | clear_list: function() { |
458 | this.tree.beginUpdateBatch(); | 458 | this.tree.beginUpdateBatch(); |
459 | this.rowCount = 0; | 459 | this.rowCount = 0; |
460 | this.files = new Array(); | 460 | this.files = new Array(); |
461 | this.tree.endUpdateBatch(); | 461 | this.tree.endUpdateBatch(); |
462 | this.selToProps(); | 462 | this.selToProps(); |
463 | }, | 463 | }, |
464 | selectionChanged: function() { | 464 | selectionChanged: function() { |
465 | this.selToProps(); | 465 | this.selToProps(); |
466 | }, | 466 | }, |
467 | disableProps: function() { | 467 | disableProps: function() { |
468 | this.upload_filename.value=''; | 468 | this.upload_filename.value=''; |
469 | this.upload_filename.disabled = true; | 469 | this.upload_filename.disabled = true; |
470 | this.upload_title.value=''; | 470 | this.upload_title.value=''; |
471 | this.upload_title.disabled = true; | 471 | this.upload_title.disabled = true; |
472 | this.upload_file_preview.src = null; | 472 | this.upload_file_preview.src = null; |
473 | this.upload_file_props.hidden = true; | 473 | this.upload_file_props.hidden = true; |
474 | this.upload_tags.value=''; | 474 | this.upload_tags.value=''; |
475 | this.upload_tags.disabled = true; | 475 | this.upload_tags.disabled = true; |
476 | }, | 476 | }, |
477 | selToProps: function() { | 477 | selToProps: function() { |
478 | if(!this.selection.count) { | 478 | if(!this.selection.count) { |
479 | this.disableProps(); | 479 | this.disableProps(); |
480 | }else if(this.selection.count==1) { | 480 | }else if(this.selection.count==1) { |
481 | var f=this.files[this.selection.currentIndex]; | 481 | var f=this.files[this.selection.currentIndex]; |
482 | if(f==null || f.state!='pending') { | 482 | if(f==null || f.state!='pending') { |
483 | this.disableProps(); | 483 | this.disableProps(); |
484 | }else{ | 484 | }else{ |
485 | this.upload_filename.value = f.file; | 485 | this.upload_filename.value = f.file; |
486 | this.upload_filename.disabled = false; | 486 | this.upload_filename.disabled = false; |
487 | this.upload_title.value = f.title; | 487 | this.upload_title.value = f.title; |
488 | this.upload_title.disabled = false; | 488 | this.upload_title.disabled = false; |
489 | this.upload_file_preview.src = 'file:///'+f.file; | 489 | this.upload_file_preview.src = 'file:///'+f.file; |
490 | this.upload_file_props.hidden = false; | 490 | this.upload_file_props.hidden = false; |
491 | this.upload_tags.value = f.tags; | 491 | this.upload_tags.value = f.tags; |
492 | this.upload_tags.disabled = false; | 492 | this.upload_tags.disabled = false; |
493 | } | 493 | } |
494 | }else{ | 494 | }else{ |
495 | var ftitle = null; var onetitle = true; | 495 | var ftitle = null; var onetitle = true; |
496 | var ftags = null; var onetag = true; | 496 | var ftags = null; var onetag = true; |
497 | var fs = 0; | 497 | var fs = 0; |
498 | for(var ff in this.files) { | 498 | for(var ff in this.files) { |
499 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { | 499 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { |
500 | ++fs; | 500 | ++fs; |
501 | if(ftitle==null) { | 501 | if(ftitle==null) { |
502 | ftitle = this.files[ff].title; | 502 | ftitle = this.files[ff].title; |
503 | }else if(ftitle!=this.files[ff].title) { | 503 | }else if(ftitle!=this.files[ff].title) { |
504 | onetitle = false; | 504 | onetitle = false; |
505 | } | 505 | } |
506 | if(ftags==null) { | 506 | if(ftags==null) { |
507 | ftags = this.files[ff].tags; | 507 | ftags = this.files[ff].tags; |
508 | }else if(ftags!=this.files[ff].tags) { | 508 | }else if(ftags!=this.files[ff].tags) { |
509 | onetag = false; | 509 | onetag = false; |
510 | } | 510 | } |
511 | } | 511 | } |
512 | } | 512 | } |
513 | if(fs) { | 513 | if(fs) { |
514 | this.upload_filename.value=''; | 514 | this.upload_filename.value=''; |
515 | this.upload_filename.disabled = true; | 515 | this.upload_filename.disabled = true; |
516 | if(onetitle) | 516 | if(onetitle) |
517 | this.upload_title.value = ftitle; | 517 | this.upload_title.value = ftitle; |
518 | this.upload_title.disabled = false; | 518 | this.upload_title.disabled = false; |
519 | if(onetag) | 519 | if(onetag) |
520 | this.upload_tags.value = ftags; | 520 | this.upload_tags.value = ftags; |
521 | this.upload_tags.disabled = false; | 521 | this.upload_tags.disabled = false; |
522 | this.upload_file_preview.src = null; | 522 | this.upload_file_preview.src = null; |
523 | this.upload_file_props.hidden = false; | 523 | this.upload_file_props.hidden = false; |
524 | }else | 524 | }else |
525 | this.disableProps(); | 525 | this.disableProps(); |
526 | } | 526 | } |
527 | }, | 527 | }, |
528 | propsToSel: function(prop) { | 528 | propsToSel: function(prop) { |
529 | if(this.selection.count<=0) return; | 529 | if(this.selection.count<=0) return; |
530 | for(var ff in this.files) { | 530 | for(var ff in this.files) { |
531 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { | 531 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { |
532 | if(prop=='filename') | 532 | if(prop=='filename') |
533 | this.files[ff].file = this.upload_filename.value; | 533 | this.files[ff].file = this.upload_filename.value; |
534 | if(prop=='title') | 534 | if(prop=='title') |
535 | this.files[ff].title = this.upload_title.value; | 535 | this.files[ff].title = this.upload_title.value; |
536 | if(prop=='tags') | 536 | if(prop=='tags') |
537 | this.files[ff].tags = this.upload_tags.value; | 537 | this.files[ff].tags = this.upload_tags.value; |
538 | this.tree.invalidateRow(ff); | 538 | this.tree.invalidateRow(ff); |
539 | } | 539 | } |
540 | } | 540 | } |
541 | }, | 541 | }, |
542 | 542 | ||
543 | on_upload: function() { | 543 | on_upload: function() { |
544 | this.selToProps(); | 544 | this.selToProps(); |
545 | this.batch_ids = new Array(); | 545 | this.batch_ids = new Array(); |
546 | this.upload_progress.value=0; | 546 | this.upload_progress.value=0; |
547 | this.upload_progress.setAttribute('hidden','false'); | 547 | this.upload_progress.setAttribute('hidden','false'); |
548 | this.upload_worker(); | 548 | this.upload_worker(); |
549 | }, | 549 | }, |
550 | on_clear: function() { | 550 | on_clear: function() { |
551 | this.clear_list(); | 551 | this.clear_list(); |
552 | }, | 552 | }, |
553 | on_remove: function() { | 553 | on_remove: function() { |
554 | if(this.selection.count) { | 554 | if(this.selection.count) { |
555 | this.tree.beginUpdateBatch(); | 555 | this.tree.beginUpdateBatch(); |
556 | for(var i=this.files.length-1;i>=0;--i) { | 556 | for(var i=this.files.length-1;i>=0;--i) { |
557 | if(this.selection.isSelected(i)) { | 557 | if(this.selection.isSelected(i)) { |
558 | this.files.splice(i,1); | 558 | this.files.splice(i,1); |
559 | this.rowCount--; | 559 | this.rowCount--; |
560 | } | 560 | } |
561 | } | 561 | } |
562 | this.tree.endUpdateBatch(); | 562 | this.tree.endUpdateBatch(); |
563 | this.selection.clearSelection(); | 563 | this.selection.clearSelection(); |
564 | } | 564 | } |
565 | }, | 565 | }, |
566 | on_add: function() { | 566 | on_add: function() { |
567 | var ifp = Components.interfaces.nsIFilePicker; | 567 | var ifp = Components.interfaces.nsIFilePicker; |
568 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); | 568 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); |
569 | fp.init(window, "Select a File", ifp.modeOpenMultiple); | 569 | fp.init(window, "Select a File", ifp.modeOpenMultiple); |
570 | fp.appendFilters(ifp.filterImages); | 570 | fp.appendFilters(ifp.filterImages); |
571 | var rv = fp.show(); | 571 | var rv = fp.show(); |
572 | if(rv==ifp.returnOK) { | 572 | if(rv==ifp.returnOK) { |
573 | var ff = fp.files; | 573 | var ff = fp.files; |
574 | while(ff.hasMoreElements()) { | 574 | while(ff.hasMoreElements()) { |
575 | var f = ff.getNext(); | 575 | var f = ff.getNext(); |
576 | f.QueryInterface(Components.interfaces.nsIFile); | 576 | f.QueryInterface(Components.interfaces.nsIFile); |
577 | this.add(f.path); | 577 | this.add(f.path); |
578 | } | 578 | } |
579 | } | 579 | } |
580 | } | 580 | } |
581 | }, | 581 | }, |
582 | 582 | ||
583 | on_set_props: function() { | 583 | on_set_props: function() { |
584 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; | 584 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; |
585 | window.openDialog( | 585 | window.openDialog( |
586 | "chrome://fireflix/content/photoset-props.xul", | 586 | "chrome://fireflix/content/photoset-props.xul", |
587 | null, "dependent,modal,dialog,chrome", this, | 587 | null, "dependent,modal,dialog,chrome", this, |
588 | pset ); | 588 | pset ); |
589 | if(pset.dirty) { | 589 | if(pset.dirty) { |
590 | var _this = this; | 590 | var _this = this; |
591 | this.flickr.api_call( | 591 | this.flickr.api_call( |
592 | { | 592 | { |
593 | method: 'flickr.photosets.editMeta', | 593 | method: 'flickr.photosets.editMeta', |
594 | auth_token: 'default', | 594 | auth_token: 'default', |
595 | photoset_id: pset.id, | 595 | photoset_id: pset.id, |
596 | title: pset.title, | 596 | title: pset.title, |
597 | description: pset.description | 597 | description: pset.description |
598 | }, function(xr) { | 598 | }, function(xr) { |
599 | pset.dirty = false; | 599 | pset.dirty = false; |
600 | _this.flickr.api_call( | 600 | _this.flickr.api_call( |
601 | { | 601 | { |
602 | method: 'flickr.photosets.getPhotos', | 602 | method: 'flickr.photosets.getPhotos', |
603 | auth_token: 'default', | 603 | auth_token: 'default', |
604 | photoset_id: pset.id | 604 | photoset_id: pset.id |
605 | }, function(xr) { | 605 | }, function(xr) { |
606 | var x = xr.responseXML; | 606 | var x = xr.responseXML; |
607 | var xp = x.evaluate( | 607 | var xp = x.evaluate( |
608 | '/rsp/photoset/photo', x, null, | 608 | '/rsp/photoset/photo', x, null, |
609 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 609 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
610 | var phids = new Array(); | 610 | var phids = new Array(); |
611 | var priph = null; | 611 | var priph = null; |
612 | var n; while(n=xp.iterateNext()) { | 612 | var n; while(n=xp.iterateNext()) { |
613 | var pid = n.getAttribute('id'); | 613 | var pid = n.getAttribute('id'); |
614 | phids.push( pid ); | 614 | phids.push( pid ); |
615 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') | 615 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') |
616 | priph = pid; | 616 | priph = pid; |
617 | } | 617 | } |
618 | if(priph) { | 618 | if(priph) { |
619 | _this.flickr.api_call( | 619 | _this.flickr.api_call( |
620 | { | 620 | { |
621 | method: 'flickr.photosets.editPhotos', | 621 | method: 'flickr.photosets.editPhotos', |
622 | auth_token: 'default', | 622 | auth_token: 'default', |
623 | photoset_id: pset.id, | 623 | photoset_id: pset.id, |
624 | primary_photo_id: priph, | 624 | primary_photo_id: priph, |
625 | photo_ids: phids.join(',') | 625 | photo_ids: phids.join(',') |
626 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ | 626 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ |
627 | _this.flickr_failure(x,s,c,m); | 627 | _this.flickr_failure(x,s,c,m); |
628 | } | 628 | } |
629 | ); | 629 | ); |
630 | } | 630 | } |
631 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ | 631 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ |
632 | _this.flickr_failure(x,s,c,m); | 632 | _this.flickr_failure(x,s,c,m); |
633 | } | 633 | } |
634 | ); | 634 | ); |
635 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ | 635 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ |
636 | _this.flickr_failure(x,s,c,m); | 636 | _this.flickr_failure(x,s,c,m); |
637 | } | 637 | } |
638 | ); | 638 | ); |
639 | } | 639 | } |
640 | }, | 640 | }, |
641 | on_refresh_sets: function() { | 641 | on_refresh_sets: function() { |
642 | this.refresh_sets(); | 642 | this.refresh_sets(); |
643 | }, | 643 | }, |
644 | on_cmd_sets_html: function(csfx,ev) { | 644 | on_cmd_sets_html: function(csfx,ev) { |
645 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 645 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
646 | var rv = this.build_html(this.photoset.photos,uti,utl); | 646 | var rv = this.build_html(this.photoset.photos,uti,utl); |
647 | this.popup_content(rv); | 647 | this.popup_content(rv); |
648 | }, | 648 | }, |
649 | 649 | ||
650 | on_cmd_uploads_html: function(csfx,ev) { | 650 | on_cmd_uploads_html: function(csfx,ev) { |
651 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 651 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
652 | var pids = new Array(); | 652 | var pids = new Array(); |
653 | for(var f in this.uploads.files) { | 653 | for(var f in this.uploads.files) { |
654 | if(this.uploads.selection.isSelected(f)) | 654 | if(this.uploads.selection.isSelected(f)) |
655 | if(this.uploads.files[f].photoid) | 655 | if(this.uploads.files[f].photoid) |
656 | pids.push(this.uploads.files[f].photoid); | 656 | pids.push(this.uploads.files[f].photoid); |
657 | } | 657 | } |
658 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; | 658 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; |
659 | var _this = this; | 659 | var _this = this; |
660 | this.flickr.api_call( | 660 | this.flickr.api_call( |
661 | { | 661 | { |
662 | method: 'flickr.photos.search', | 662 | method: 'flickr.photos.search', |
663 | auth_token: 'default', | 663 | auth_token: 'default', |
664 | extras: 'original_format', | 664 | extras: 'original_format', |
665 | user_id: 'me', | 665 | user_id: 'me', |
666 | per_page: pp | 666 | per_page: pp |
667 | }, | 667 | }, |
668 | function(xr) { | 668 | function(xr) { |
669 | var x = xr.responseXML; | 669 | var x = xr.responseXML; |
670 | var rv = ''; | 670 | var rv = ''; |
671 | for(var pn in pids) { | 671 | for(var pn in pids) { |
672 | var p = pids[pn]; | 672 | var p = pids[pn]; |
673 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); | 673 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); |
674 | rv += _this.photo_html(pp,uti,utl)+'\n'; | 674 | rv += _this.photo_html(pp,uti,utl)+'\n'; |
675 | } | 675 | } |
676 | _this.popup_content(rv); | 676 | _this.popup_content(rv); |
677 | }, function(x,s,c,m) { | 677 | }, function(x,s,c,m) { |
678 | _this.flickr_failure(x,s,c,m); | 678 | _this.flickr_failure(x,s,c,m); |
679 | } | 679 | } |
680 | ); | 680 | ); |
681 | }, | 681 | }, |
682 | 682 | ||
683 | /* | 683 | /* |
684 | * | 684 | * |
685 | */ | 685 | */ |
686 | foundphotos: { | 686 | foundphotos: { |
687 | fireflix: null, | 687 | fireflix: null, |
688 | init: function(f) { | 688 | init: function(f) { |
689 | this.fireflix = f; | 689 | this.fireflix = f; |
690 | pull_elements(this,document,[ | 690 | pull_elements(this,document,[ |
691 | 'search_for','search_tags','search_mine', | 691 | 'search_for','search_tags','search_mine', |
692 | 'searchresult_props','search_photo', | 692 | 'searchresult_props','search_photo', |
693 | 'searchresult_title','searchresult_description' | 693 | 'searchresult_title','searchresult_description' |
694 | ]); | 694 | ]); |
695 | document.getElementById('searchresults').view = this; | 695 | document.getElementById('searchresults').view = this; |
696 | }, | 696 | }, |
697 | photos: new Array(), | 697 | photos: new Array(), |
698 | rowCount: 0, | 698 | rowCount: 0, |
699 | getCellText: function(r,c) { | 699 | getCellText: function(r,c) { |
700 | var p = this.photos[r]; | 700 | var p = this.photos[r]; |
701 | if(c.id=='sr_title') return p.title; | 701 | if(c.id=='sr_title') return p.title; |
702 | return c.id; | 702 | return c.id; |
703 | }, | 703 | }, |
704 | setTree: function(t) { this.tree = t }, | 704 | setTree: function(t) { this.tree = t }, |
705 | isContainer: function(r) { return false }, | 705 | isContainer: function(r) { return false }, |
706 | isSeparator: function(r) { return false }, | 706 | isSeparator: function(r) { return false }, |
707 | isSorted: function(r) { return false }, | 707 | isSorted: function(r) { return false }, |
708 | getLevel: function(r) { return 0 }, | 708 | getLevel: function(r) { return 0 }, |
709 | getImageSrc: function(r,c) { return null }, | 709 | getImageSrc: function(r,c) { return null }, |
710 | getRowProperties: function(r,p) { }, | 710 | getRowProperties: function(r,p) { }, |
711 | getCellProperties: function(cid,cel,p) { }, | 711 | getCellProperties: function(cid,cel,p) { }, |
712 | getColumnProperties: function(cid,cel,p) { }, | 712 | getColumnProperties: function(cid,cel,p) { }, |
713 | cycleHeader: function(cid,e) { }, | 713 | cycleHeader: function(cid,e) { }, |
714 | getParentIndex: function(r) { return -1 }, | 714 | getParentIndex: function(r) { return -1 }, |
715 | drop: function(r,o) { }, | 715 | drop: function(r,o) { }, |
716 | canDropBeforeAfter: function(r,b) { return false }, | 716 | canDropBeforeAfter: function(r,b) { return false }, |
717 | 717 | ||
718 | importXPR: function(xp) { | 718 | importXPR: function(xp) { |
719 | this.selection.clearSelection(); | 719 | this.selection.clearSelection(); |
720 | this.selection.currentIndex = -1; | 720 | this.selection.currentIndex = -1; |
721 | this.searchresult_props.hidden = true; | 721 | this.searchresult_props.hidden = true; |
722 | this.tree.beginUpdateBatch(); | 722 | this.tree.beginUpdateBatch(); |
723 | this.photos = new Array(); | 723 | this.photos = new Array(); |
724 | var n; while(n=xp.iterateNext()) { | 724 | var n; while(n=xp.iterateNext()) { |
725 | this.photos.push(new Photo(n)); | 725 | this.photos.push(new Photo(n)); |
726 | } | 726 | } |
727 | this.rowCount = this.photos.length; | 727 | this.rowCount = this.photos.length; |
728 | this.tree.endUpdateBatch(); | 728 | this.tree.endUpdateBatch(); |
729 | }, | 729 | }, |
730 | search_photos: function() { | 730 | search_photos: function() { |
731 | var pars = { | 731 | var pars = { |
732 | method: 'flickr.photos.search', | 732 | method: 'flickr.photos.search', |
733 | auth_token: 'default', | 733 | auth_token: 'default', |
734 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' | 734 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' |
735 | }; | 735 | }; |
736 | if(this.search_mine.checked) | 736 | if(this.search_mine.checked) |
737 | pars.user_id='me'; | 737 | pars.user_id='me'; |
738 | if(this.search_tags.checked) { | 738 | if(this.search_tags.checked) { |
739 | pars.tags=this.search_for.value.split(/ +/).join(','); | 739 | pars.tags=this.search_for.value.split(/ +/).join(','); |
740 | }else{ | 740 | }else{ |
741 | pars.text=this.search_for.value; | 741 | pars.text=this.search_for.value; |
742 | } | 742 | } |
743 | var _this = this; | 743 | var _this = this; |
744 | this.fireflix.flickr.api_call( pars, | 744 | this.fireflix.flickr.api_call( pars, |
745 | function(xr) { | 745 | function(xr) { |
746 | var x = xr.responseXML; | 746 | var x = xr.responseXML; |
747 | var xp = x.evaluate( | 747 | var xp = x.evaluate( |
748 | '/rsp/photos/photo', x, null, | 748 | '/rsp/photos/photo', x, null, |
749 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 749 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
750 | _this.importXPR(xp); | 750 | _this.importXPR(xp); |
751 | _this.tree.ensureRowIsVisible(0); | ||
751 | _this.on_select(); | 752 | _this.on_select(); |
752 | }, function(x,s,c,m) { | 753 | }, function(x,s,c,m) { |
753 | _this.fireflix.flickr_failure(x,s,c,m); | 754 | _this.fireflix.flickr_failure(x,s,c,m); |
754 | } | 755 | } |
755 | ); | 756 | ); |
756 | }, | 757 | }, |
757 | render_description_frame: function(content) { | 758 | render_description_frame: function(content) { |
758 | if(!content) { | 759 | if(!content) { |
759 | this.searchresult_description.innerHTML = ''; | 760 | this.searchresult_description.innerHTML = ''; |
760 | }else{ | 761 | }else{ |
761 | this.searchresult_description.innerHTML = content?content:''; | 762 | this.searchresult_description.innerHTML = content?content:''; |
762 | /* of all linking elements flickr only allows a */ | 763 | /* of all linking elements flickr only allows a */ |
763 | var as = this.searchresult_description.getElementsByTagName('a'); | 764 | var as = this.searchresult_description.getElementsByTagName('a'); |
764 | for(var a=0;a<as.length;++a) | 765 | for(var a=0;a<as.length;++a) |
765 | as.item(a).setAttribute('target','_blank'); | 766 | as.item(a).setAttribute('target','_blank'); |
766 | } | 767 | } |
767 | }, | 768 | }, |
768 | on_select: function() { | 769 | on_select: function() { |
769 | if(this.selection.currentIndex<0) { | 770 | if(this.selection.currentIndex<0) { |
770 | this.searchresult_props.hidden = true; | 771 | this.searchresult_props.hidden = true; |
771 | }else{ | 772 | }else{ |
772 | var p = this.photos[this.selection.currentIndex]; | 773 | var p = this.photos[this.selection.currentIndex]; |
773 | if(!p) { | 774 | if(!p) { |
774 | this.searchresult_props.hidden = true; | 775 | this.searchresult_props.hidden = true; |
775 | }else{ | 776 | }else{ |
776 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); | 777 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); |
777 | this.searchresult_title.value = p.title; | 778 | this.searchresult_title.value = p.title; |
778 | this.render_description_frame(null); | 779 | this.render_description_frame(null); |
779 | if(p.description==null && p.description==undefined) { | 780 | if(p.description==null && p.description==undefined) { |
780 | var pid = p.id; | 781 | var pid = p.id; |
781 | var ci = this.selection.currentIndex; | 782 | var ci = this.selection.currentIndex; |
782 | var _this = this; | 783 | var _this = this; |
783 | this.fireflix.flickr.api_call( | 784 | this.fireflix.flickr.api_call( |
784 | { | 785 | { |
785 | method: 'flickr.photos.getInfo', | 786 | method: 'flickr.photos.getInfo', |
786 | auth_token: 'default', | 787 | auth_token: 'default', |
787 | photo_id: p.id, | 788 | photo_id: p.id, |
788 | secret: p.secret | 789 | secret: p.secret |
789 | }, function(xr) { | 790 | }, function(xr) { |
790 | var pp = _this.photos[ci]; | 791 | var pp = _this.photos[ci]; |
791 | if(ci==_this.selection.currentIndex && pp.id==pid) { | 792 | if(ci==_this.selection.currentIndex && pp.id==pid) { |
792 | var n = xp_node('/rsp/photo',xr.responseXML); | 793 | var n = xp_node('/rsp/photo',xr.responseXML); |
793 | pp.fromNode_(n); | 794 | pp.fromNode_(n); |
794 | _this.render_description_frame(pp.description); | 795 | _this.render_description_frame(pp.description); |
795 | } | 796 | } |
796 | }, function(x,s,c,m) { | 797 | }, function(x,s,c,m) { |
797 | _this.fireflix.flickr_failure(x,s,c,m); | 798 | _this.fireflix.flickr_failure(x,s,c,m); |
798 | } | 799 | } |
799 | ); | 800 | ); |
800 | this.searchresult_props.hidden = false; | 801 | this.searchresult_props.hidden = false; |
801 | }else{ | 802 | }else{ |
802 | this.render_description_frame(p.description); | 803 | this.render_description_frame(p.description); |
803 | } | 804 | } |
804 | } | 805 | } |
805 | } | 806 | } |
806 | }, | 807 | }, |
807 | on_cmd_open: function(ev) { | 808 | on_cmd_open: function(ev) { |
808 | if(this.selection.currentIndex<0) | 809 | if(this.selection.currentIndex<0) |
809 | return; | 810 | return; |
810 | var p = this.photos[this.selection.currentIndex]; | 811 | var p = this.photos[this.selection.currentIndex]; |
811 | if(!p.id) | 812 | if(!p.id) |
812 | return; | 813 | return; |
813 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); | 814 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); |
814 | } | 815 | } |
815 | }, | 816 | }, |
816 | 817 | ||
817 | photo_html: function(p,i,l) { | 818 | photo_html: function(p,i,l) { |
818 | // TODO: add alt/title when possible | 819 | // TODO: add alt/title when possible |
819 | var rv = | 820 | var rv = |
820 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + | 821 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + |
821 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ | 822 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ |
822 | '</a>'; | 823 | '</a>'; |
823 | return rv; | 824 | return rv; |
824 | }, | 825 | }, |
825 | build_html: function(photos,uti,utl) { | 826 | build_html: function(photos,uti,utl) { |
826 | var rv = ''; | 827 | var rv = ''; |
827 | for(var i in photos) { | 828 | for(var i in photos) { |
828 | var p = photos[i]; | 829 | var p = photos[i]; |
829 | rv += this.photo_html(p,utl,uti)+'\n'; | 830 | rv += this.photo_html(p,utl,uti)+'\n'; |
830 | } | 831 | } |
831 | return rv; | 832 | return rv; |
832 | }, | 833 | }, |
833 | 834 | ||
834 | popup_content: function(s) { | 835 | popup_content: function(s) { |
835 | window.openDialog( | 836 | window.openDialog( |
836 | "chrome://fireflix/content/generated-content.xul", | 837 | "chrome://fireflix/content/generated-content.xul", |
837 | null, "dialog,chrome", this, s ); | 838 | null, "dialog,chrome", this, s ); |
838 | }, | 839 | }, |
839 | copy_to_clipboard: function(s) { | 840 | copy_to_clipboard: function(s) { |
840 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] | 841 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] |
841 | .getService(Components.interfaces.nsIClipboardHelper); | 842 | .getService(Components.interfaces.nsIClipboardHelper); |
842 | ch.copyString(s); | 843 | ch.copyString(s); |
843 | }, | 844 | }, |
844 | openTab: function(l) { | 845 | openTab: function(l) { |
845 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( | 846 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( |
846 | Components.interfaces.nsIWindowMediator ); | 847 | Components.interfaces.nsIWindowMediator ); |
847 | var bw = wm.getMostRecentWindow('navigator:browser'); | 848 | var bw = wm.getMostRecentWindow('navigator:browser'); |
848 | var b = bw.getBrowser(); | 849 | var b = bw.getBrowser(); |
849 | var t = b.addTab(l); | 850 | var t = b.addTab(l); |
850 | b.selectedTab = t; | 851 | b.selectedTab = t; |
851 | }, | 852 | }, |
852 | 853 | ||
853 | build_menus: function() { | 854 | build_menus: function() { |
854 | this.append_html_menu( | 855 | this.append_html_menu( |
855 | document.getElementById('sets_html_menu'), | 856 | document.getElementById('sets_html_menu'), |
856 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' | 857 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' |
857 | ); | 858 | ); |
858 | this.append_html_menu( | 859 | this.append_html_menu( |
859 | document.getElementById('uploads_html_menu'), | 860 | document.getElementById('uploads_html_menu'), |
860 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' | 861 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' |
861 | ); | 862 | ); |
862 | return; | 863 | return; |
863 | }, | 864 | }, |
864 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { | 865 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { |
865 | var mp = m.appendChild(document.createElement('menupopup')); | 866 | var mp = m.appendChild(document.createElement('menupopup')); |
866 | var t; | 867 | var t; |
867 | t=mp.appendChild(document.createElement('menuitem')); | 868 | t=mp.appendChild(document.createElement('menuitem')); |
868 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); | 869 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); |
869 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 870 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
870 | mp.appendChild(document.createElement('menuseparator')); | 871 | mp.appendChild(document.createElement('menuseparator')); |
871 | var cs = document.getElementById(csid); | 872 | var cs = document.getElementById(csid); |
872 | for(var iti=0;iti<imgt.length;++iti) { | 873 | for(var iti=0;iti<imgt.length;++iti) { |
873 | t = mp.appendChild(document.createElement('menu')); | 874 | t = mp.appendChild(document.createElement('menu')); |
874 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); | 875 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); |
875 | var smp = t.appendChild(document.createElement('menupopup')); | 876 | var smp = t.appendChild(document.createElement('menupopup')); |
876 | t=smp.appendChild(document.createElement('menuitem')); | 877 | t=smp.appendChild(document.createElement('menuitem')); |
877 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); | 878 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); |
878 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 879 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
879 | smp.appendChild(document.createElement('menuseparator')); | 880 | smp.appendChild(document.createElement('menuseparator')); |
880 | for(var lti=0;lti<lnkt.length;++lti) { | 881 | for(var lti=0;lti<lnkt.length;++lti) { |
881 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); | 882 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); |
882 | t=smp.appendChild(document.createElement('menuitem')); | 883 | t=smp.appendChild(document.createElement('menuitem')); |
883 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); | 884 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); |
884 | t.setAttribute('command',cpfx+'_'+csfx); | 885 | t.setAttribute('command',cpfx+'_'+csfx); |
885 | t=cs.appendChild(document.createElement('command')); | 886 | t=cs.appendChild(document.createElement('command')); |
886 | t.setAttribute('id',cpfx+'_'+csfx); | 887 | t.setAttribute('id',cpfx+'_'+csfx); |
887 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); | 888 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); |
888 | } | 889 | } |
889 | } | 890 | } |
890 | return mp; | 891 | return mp; |
891 | }, | 892 | }, |
892 | 893 | ||
893 | flickr_failure: function(x,s,c,m) { | 894 | flickr_failure: function(x,s,c,m) { |
894 | if(c==98) { // Invalid auth token | 895 | if(c==98) { // Invalid auth token |
895 | this.flickr.reset_token(); | 896 | this.flickr.reset_token(); |
896 | this.set_auth_state(false,false); | 897 | this.set_auth_state(false,false); |
897 | return; | 898 | return; |
898 | } | 899 | } |
899 | // TODO: is that beauty? | 900 | // TODO: is that beauty? |
900 | alert('flickr api call failed\n'+c+' '+m); | 901 | alert('flickr api call failed\n'+c+' '+m); |
901 | } | 902 | } |
902 | 903 | ||
903 | }; | 904 | }; |