diff options
author | Yorhel <git@yorhel.nl> | 2008-12-04 13:02:26 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2008-12-04 13:02:26 +0100 |
commit | 41d31eb3eb4576cf7e621cd254b6cefe347981fc (patch) | |
tree | d26450cd86100cd48321f08a9e0f283cf38412c9 | |
parent | 8e606a77e4be57ed45286cdc9d939fc7c1f1c739 (diff) |
...and an interface for adding/removing producers
Code reuse = good.
Release edit form is now finished, functionality-wise.
-rw-r--r-- | lib/VNDB/Handler/Producers.pm | 27 | ||||
-rw-r--r-- | lib/VNDB/Handler/Releases.pm | 12 | ||||
-rw-r--r-- | static/f/forms.js | 85 | ||||
-rw-r--r-- | static/f/script.js | 4 | ||||
-rw-r--r-- | static/f/style.css | 14 |
5 files changed, 93 insertions, 49 deletions
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm index d3e37a36..49a7b879 100644 --- a/lib/VNDB/Handler/Producers.pm +++ b/lib/VNDB/Handler/Producers.pm @@ -3,7 +3,7 @@ package VNDB::Handler::Producers; use strict; use warnings; -use YAWF ':html'; +use YAWF ':html', ':xml'; use VNDB::Func; @@ -12,6 +12,7 @@ YAWF::register( qr{p(?:([1-9]\d*)(?:\.([1-9]\d*))?/edit|/new)} => \&edit, qr{p/([a-z0]|all)} => \&list, + qr{xml/producers\.xml} => \&pxml, ); @@ -205,5 +206,29 @@ sub list { } +# peforms a (simple) search and returns the results in XML format +sub pxml { + my $self = shift; + + my $q = $self->formValidate({ name => 'q', maxlength => 500 }); + return 404 if $q->{_err}; + $q = $q->{q}; + + my($list, $np) = $self->dbProducerGet( + $q =~ /^p([1-9]\d*)/ ? (id => $1) : (search => $q), + results => 10, + page => 1, + ); + + $self->resHeader('Content-type' => 'text/xml; charset=UTF-8'); + xml; + tag 'producers', more => $np ? 'yes' : 'no', query => $q; + for(@$list) { + tag 'item', id => $_->{id}, $_->{name}; + } + end; +} + + 1; diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm index 52cbde84..55ce8400 100644 --- a/lib/VNDB/Handler/Releases.pm +++ b/lib/VNDB/Handler/Releases.pm @@ -349,7 +349,17 @@ sub _form { ], 'Producers' => [ - [ input => short => 'producers', name => 'Producers' ], + [ hidden => short => 'producers' ], + [ static => nolabel => 1, content => sub { + h2 'Selected producers'; + div id => 'producerssel'; + end; + h2 'Add producer'; + div; + input type => 'text', class => 'text'; + a href => '#', 'add'; + end; + }], ], 'Visual novels' => [ diff --git a/static/f/forms.js b/static/f/forms.js index 0ea4c3a3..f49c0d23 100644 --- a/static/f/forms.js +++ b/static/f/forms.js @@ -742,23 +742,24 @@ function medSerialize() { - /*******************************\ - * V I S U A L N O V E L S * - \*******************************/ + /****************************************************\ + * V I S U A L N O V E L S / P R O D U C E R S * + \****************************************************/ -function vnrLoad() { +function vnpLoad(type) { // load currently selected VNs - var l = x('vn').value.split('|||'); + var l = x(type).value.split('|||'); for(var i=0;i<l.length;i++) if(l[i].length > 2) - vnrAdd(l[i].split(',',2)[0], l[i].split(',',2)[1]); + vnpAdd(type, l[i].split(',',2)[0], l[i].split(',',2)[1]); + vnpCheckEmpty(type); // dropdown - var n = x('jt_box_visual_novels').getElementsByTagName('div')[1]; - dsInit(n.getElementsByTagName('input')[0], '/xml/vn.xml?q=', function(item, tr) { + var n = x('jt_box_'+(type == 'vn' ? 'visual_novels' : type)).getElementsByTagName('div')[1]; + dsInit(n.getElementsByTagName('input')[0], '/xml/'+type+'.xml?q=', function(item, tr) { var td = document.createElement('td'); - td.innerHTML = 'v'+item.getAttribute('id'); + td.innerHTML = type.substr(0,1)+item.getAttribute('id'); td.style.textAlign = 'right'; td.style.paddingRight = '5px'; tr.appendChild(td); @@ -766,80 +767,86 @@ function vnrLoad() { td.innerHTML = shorten(item.firstChild.nodeValue, 40); tr.appendChild(td); }, function(item) { - return 'v'+item.getAttribute('id')+':'+item.firstChild.nodeValue; - }, vnrFormAdd); + return type.substr(0,1)+item.getAttribute('id')+':'+item.firstChild.nodeValue; + }, function() { vnpFormAdd(type) }); + n.getElementsByTagName('a')[0].onclick = function() { vnpFormAdd(type); return false }; } -function vnrAdd(vid, title) { +function vnpAdd(type, id, title) { var o = document.createElement('span'); - o.innerHTML = '<i>v'+vid+':<a href="/v'+vid+'">'+shorten(title, 40)+'</a></i>' - +'<a href="#" onclick="return vnrDel(this)">remove</a>'; - x('vnsel').appendChild(o); - vnrStripe(); - vnrCheckEmpty(); + o.innerHTML = '<i>'+type.substr(0,1)+id+':<a href="/'+type.substr(0,1)+id+'">'+shorten(title, 40)+'</a></i>' + +'<a href="#" onclick="return vnpDel(this, \''+type+'\')">remove</a>'; + x(type+'sel').appendChild(o); + vnpStripe(type); + vnpCheckEmpty(type); } -function vnrDel(what) { +function vnpDel(what, type) { what = what.nodeName ? what : this; while(what.nodeName.toLowerCase() != 'span') what = what.parentNode; - x('vnsel').removeChild(what); - vnrCheckEmpty(); - vnrSerialize(); + x(type+'sel').removeChild(what); + vnpCheckEmpty(type); + vnpSerialize(type); return false; } -function vnrCheckEmpty() { - if(x('vnsel').getElementsByTagName('span').length < 1) { - if(x('vnsel').getElementsByTagName('b').length < 1) - x('vnsel').innerHTML = '<b>Nothing selected...</b>'; - } else if(x('vnsel').getElementsByTagName('b').length == 1) - x('vnsel').removeChild(x('vnsel').getElementsByTagName('b')[0]); +function vnpCheckEmpty(type) { + var o = x(type+'sel'); + if(o.getElementsByTagName('span').length < 1) { + if(o.getElementsByTagName('b').length < 1) + o.innerHTML = '<b>Nothing selected...</b>'; + } else if(o.getElementsByTagName('b').length == 1) + o.removeChild(o.getElementsByTagName('b')[0]); } -function vnrStripe() { - var l = x('vnsel').getElementsByTagName('span'); +function vnpStripe(type) { + var l = x(type+'sel').getElementsByTagName('span'); for(var i=0;i<l.length;i++) l[i].className = i%2 ? 'odd' : ''; } -function vnrFormAdd() { - var n = x('jt_box_visual_novels').getElementsByTagName('div')[1]; +function vnpFormAdd(type) { + var n = x('jt_box_'+(type == 'vn' ? 'visual_novels' : type)).getElementsByTagName('div')[1]; var txt = n.getElementsByTagName('input')[0]; var lnk = n.getElementsByTagName('a')[0]; var input = txt.value; - if(!input.match(/^v[0-9]+/)) { + if(type == 'vn' && !input.match(/^v[0-9]+/)) { alert('Visual novel textbox must start with an ID (e.g. v17)'); return false; } + if(type == 'producers' && !input.match(/^p[0-9]+/)) { + alert('Producer textbox must start with an ID (e.g. p5)'); + return false; + } txt.disabled = true; txt.value = 'loading...'; lnk.innerHTML = 'loading...'; - ajax('/xml/vn.xml?q='+encodeURIComponent(input), function(hr) { + ajax('/xml/'+type+'.xml?q='+encodeURIComponent(input), function(hr) { txt.disabled = false; txt.value = ''; lnk.innerHTML = 'add'; var items = hr.responseXML.getElementsByTagName('item'); if(items.length < 1) - return alert('Visual novel not found!'); + return alert('Item not found!'); - vnrAdd(items[0].getAttribute('id'), items[0].firstChild.nodeValue); - vnrSerialize(); + vnpAdd(type, items[0].getAttribute('id'), items[0].firstChild.nodeValue); + vnpSerialize(type); }); return false; } -function vnrSerialize() { +function vnpSerialize(type) { var r = ''; - var l = x('vnsel').getElementsByTagName('span'); + var l = x(type+'sel').getElementsByTagName('span'); for(var i=0;i<l.length;i++) r += (r ? '|||' : '') + l[i].getElementsByTagName('i')[0].innerHTML.substr(1, l[i].getElementsByTagName('i')[0].innerHTML.indexOf(':')-1) + ',' + l[i].getElementsByTagName('a')[0].innerHTML; - x('vn').value = r; + x(type).value = r; } diff --git a/static/f/script.js b/static/f/script.js index 43f54fe4..8c0e3d0f 100644 --- a/static/f/script.js +++ b/static/f/script.js @@ -305,7 +305,9 @@ DOMLoad(function() { if(x('media')) medLoad(); if(x('jt_box_visual_novels')) - vnrLoad(); + vnpLoad('vn'); + if(x('jt_box_producers')) + vnpLoad('producers'); // spam protection on all forms if(document.forms.length >= 1) diff --git a/static/f/style.css b/static/f/style.css index de17dcf0..85a58da4 100644 --- a/static/f/style.css +++ b/static/f/style.css @@ -766,13 +766,13 @@ ul#catselect li li.exc { background-position: 0px -33px; color: #c00; } #media_div { padding-left: 20px; } #media_div span { display: block } -#jt_box_visual_novels h2 { clear: left; padding-top: 10px; } -#jt_box_visual_novels div { padding-left: 20px } -#jt_box_visual_novels input { margin-right: 10px; width: 300px } -#jt_box_visual_novels span { clear: left; display: block; padding: 2px; } -#jt_box_visual_novels span.odd { background: url(/f/boxbg.png) repeat; } -#jt_box_visual_novels i { font-style: normal; display: block; float: left; width: 310px } -#jt_box_visual_novels b { font-weight: normal; } +#jt_box_visual_novels h2, #jt_box_producers h2 { clear: left; padding-top: 10px; } +#jt_box_visual_novels div, #jt_box_producers div { padding-left: 20px } +#jt_box_visual_novels input, #jt_box_producers input { margin-right: 10px; width: 300px } +#jt_box_visual_novels span, #jt_box_producers span { clear: left; display: block; padding: 2px; } +#jt_box_visual_novels span.odd, #jt_box_producers span.odd { background: url(/f/boxbg.png) repeat; } +#jt_box_visual_novels i, #jt_box_producers i { font-style: normal; display: block; float: left; width: 310px } +#jt_box_visual_novels b, #jt_box_producers b { font-weight: normal; } |