summaryrefslogtreecommitdiffabout
path: root/content
authorMichael Krelin <hacker@klever.net>2006-10-01 23:53:31 (UTC)
committer Michael Krelin <hacker@klever.net>2006-10-01 23:53:31 (UTC)
commitb6a122d536aef024b69d40cdf2ac0332d7c14607 (patch) (side-by-side diff)
tree5b6f01eb73f858e6caaf22301e23d7b6b996ffea /content
parent455df70118b045c6053b33ae2f0318a70e4f96b8 (diff)
downloadfireflix-b6a122d536aef024b69d40cdf2ac0332d7c14607.zip
fireflix-b6a122d536aef024b69d40cdf2ac0332d7c14607.tar.gz
fireflix-b6a122d536aef024b69d40cdf2ac0332d7c14607.tar.bz2
paginating through search results
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@179 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (limited to 'content') (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix-panel.xul13
-rw-r--r--content/fireflix.css10
-rw-r--r--content/fireflix.js50
-rw-r--r--content/util.js7
4 files changed, 75 insertions, 5 deletions
diff --git a/content/fireflix-panel.xul b/content/fireflix-panel.xul
index 398dd78..bf6df73 100644
--- a/content/fireflix-panel.xul
+++ b/content/fireflix-panel.xul
@@ -39,24 +39,30 @@
<menuitem command="cmd_auth_done" hidden="true" id="menu_auth_done"/>
<menuitem command="cmd_auth_unauth" />
<menuseparator/>
<menuitem command="cmd_auth_open_flickr"/>
</popup>
</popupset>
<commandset id="cmdset_search">
<command id="cmd_search" label="&panel.search.cmd_search.label;"
oncommand="fireflix.foundphotos.search_photos()"/>
<command id="cmd_search_open" label="&panel.search.cmd_search_open.label;"
oncommand="fireflix.foundphotos.on_cmd_open(event)" />
+ <command id="cmd_search_prev_page"
+ label="&panel.search.cmd_search_prev_page.label;"
+ oncommand="fireflix.foundphotos.on_cmd_prev(event)" disabled="true"/>
+ <command id="cmd_search_next_page"
+ label="&panel.search.cmd_search_next_page.label;"
+ oncommand="fireflix.foundphotos.on_cmd_next(event)" disabled="true"/>
</commandset>
<commandset id="cmdset_sets">
<command id="cmd_refresh_sets" label="&panel.sets.cmd_refresh_sets;"
oncommand="fireflix.on_refresh_sets()" />
<command id="cmd_set_props" label="&panel.sets.cmd_properties;"
oncommand="fireflix.on_set_props()" disabled="true" />
</commandset>
<popupset>
<popup id="sets_menu">
<menuitem command="cmd_set_props"/>
@@ -121,24 +127,31 @@
accesskey="s"/>
<textbox id="search_for" flex="1"/>
</hbox>
<hbox>
<checkbox id="search_tags" label="&panel.search.mode.tagsonly.label;"
tooltiptext="&panel.search.mode.tagsonly.tip;" checked="false"
accesskey="t" />
<checkbox id="search_mine" label="&panel.search.mode.mine.label;" checked="true" accesskey="m"/>
<spacer flex="1"/>
<button command="cmd_search"/>
</hbox>
</groupbox>
+ <hbox>
+ <button command="cmd_search_prev_page"/>
+ <spacer flex="1"/>
+ <label id="search_page" hidden="true"/>
+ <spacer flex="1"/>
+ <button command="cmd_search_next_page"/>
+ </hbox>
<tree id="searchresults" rows="2" flex="1"
onselect="fireflix.foundphotos.on_select()"
ondblclick="fireflix.foundphotos.on_cmd_open(event)"
onkeypress="if(event.keyCode==event.DOM_VK_RETURN)
fireflix.foundphotos.on_cmd_open(event)">
<treecols>
<treecol id="sr_title" label="&panel.search.col.title.label;" flex="2" crop="end" align="start" />
</treecols>
<treechildren/>
</tree>
<groupbox id="searchresult_props" orient="horizontal" hidden="true">
<vbox width="100" pack="center">
diff --git a/content/fireflix.css b/content/fireflix.css
index 71080d1..9e7bf6b 100644
--- a/content/fireflix.css
+++ b/content/fireflix.css
@@ -78,12 +78,22 @@ div#searchresult_description {
font-size: 90%;
margin: 0.1ex 0.5ex;
}
#copying div {
margin: 1ex 1em;
font-family: courier, monospace;
font-size: 9pt;
padding: 2px;
border: dotted 1px gray;
background: white;
}
+
+label#search_page {
+ font-weight: bold;
+ background: white; color: #404040;
+ border-color: #c0c0c0 #404040 #404040 #c0c0c0;
+ border-style: solid;
+ border-width: 1px;
+ -moz-border-radius: 1em;
+ padding: 0.5ex 1ex;
+}
diff --git a/content/fireflix.js b/content/fireflix.js
index e144aae..92c42f4 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -683,25 +683,26 @@ var fireflix = {
},
/*
*
*/
foundphotos: {
fireflix: null,
init: function(f) {
this.fireflix = f;
pull_elements(this,document,[
'search_for','search_tags','search_mine',
'searchresult_props','search_photo',
- 'searchresult_title','searchresult_description'
+ 'searchresult_title','searchresult_description',
+ 'search_page','cmd_search_prev_page','cmd_search_next_page'
]);
document.getElementById('searchresults').view = this;
},
photos: new Array(),
rowCount: 0,
getCellText: function(r,c) {
var p = this.photos[r];
if(c.id=='sr_title') return p.title;
return c.id;
},
setTree: function(t) { this.tree = t },
isContainer: function(r) { return false },
@@ -720,52 +721,91 @@ var fireflix = {
importXPR: function(xp) {
this.selection.clearSelection();
this.selection.currentIndex = -1;
this.searchresult_props.hidden = true;
this.tree.beginUpdateBatch();
this.photos = new Array();
var n; while(n=xp.iterateNext()) {
this.photos.push(new Photo(n));
}
this.rowCount = this.photos.length;
this.tree.endUpdateBatch();
},
+ paging: {
+ pars: null,
+ page: null, pages: null, perpage: null, total: null
+ },
search_photos: function() {
var pars = {
method: 'flickr.photos.search',
auth_token: 'default',
extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo'
};
if(this.search_mine.checked)
pars.user_id='me';
if(this.search_tags.checked) {
pars.tags=this.search_for.value.split(/ +/).join(',');
}else{
pars.text=this.search_for.value;
}
+ this.paging.pars = new Object();
+ this.paging.page = null; this.paging.pages = null;
+ this.paging.perpage = null; this.paging.total = null;
+ for(var p in pars) this.paging.pars[p] = pars[p];
+ this.perform_search(pars);
+ },
+ perform_search: function(p) {
var _this = this;
- this.fireflix.flickr.api_call( pars,
+ this.fireflix.flickr.api_call( p,
function(xr) {
var x = xr.responseXML;
- var xp = x.evaluate(
- '/rsp/photos/photo', x, null,
- XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
+ var xp = xp_nodes('/rsp/photos/photo',x);
_this.importXPR(xp);
_this.tree.ensureRowIsVisible(0);
+ xp = xp_node('/rsp/photos',x);
+ _this.paging.page = parseInt(xp.getAttribute('page'));
+ _this.paging.pages = parseInt(xp.getAttribute('pages'));
+ _this.paging.perpage = parseInt(xp.getAttribute('perpage'));
+ _this.paging.total = parseInt(xp.getAttribute('total'));
+ _this.update_paging();
_this.on_select();
}, function(x,s,c,m) {
_this.fireflix.flickr_failure(x,s,c,m);
}
);
},
+ on_cmd_prev: function(ev) {
+ var pars = new Object();
+ for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
+ pars.page=this.paging.page-1; pars.per_page=this.paging.perpage;
+ this.perform_search(pars);
+ },
+ on_cmd_next: function(ev) {
+ var pars = new Object();
+ for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
+ pars.page=this.paging.page+1; pars.per_page=this.paging.perpage;
+ this.perform_search(pars);
+ },
+ update_paging: function() {
+ if(! (this.paging.pars && this.paging.page && this.paging.pages) ) {
+ this.search_page.value=''; this.search_page.hidden = true;
+ this.cmd_search_prev_page.setAttribute('disabled','true');
+ this.cmd_search_next_page.setAttribute('disabled','true');
+ }else{
+ this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]);
+ this.search_page.hidden=false;
+ this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true');
+ this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true');
+ }
+ },
render_description_frame: function(content) {
if(!content) {
this.searchresult_description.innerHTML = '';
}else{
this.searchresult_description.innerHTML = content?content:'';
/* of all linking elements flickr only allows a */
var as = this.searchresult_description.getElementsByTagName('a');
for(var a=0;a<as.length;++a)
as.item(a).setAttribute('target','_blank');
}
},
on_select: function() {
diff --git a/content/util.js b/content/util.js
index c4af09e..ccc61cf 100644
--- a/content/util.js
+++ b/content/util.js
@@ -49,22 +49,29 @@ function xp_str(xp,x) {
var rv = x.evaluate(
xp, x, null, XPathResult.STRING_TYPE, null );
return rv.stringValue;
}
/*
* extract xpath-specified node
*/
function xp_node(xp,x) {
var rv = x.evaluate(
xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null );
return rv.singleNodeValue;
}
+/*
+ * extract xpath-specified ordered set of nodes
+ */
+function xp_nodes(xp,x) {
+ return x.evaluate(
+ xp, x, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
+}
/*
* pull in elements into documents as a member variables
*/
function pull_elements(th,d,els) {
for(var e in els) {
var en=els[e];
th[en] = d.getElementById(en);
}
}