diff options
author | Yorhel <git@yorhel.nl> | 2009-10-21 13:37:42 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-10-21 13:37:42 +0200 |
commit | 2301f0d2c726a1352494ad0f3bba8c5138b4fedd (patch) | |
tree | 1feecf14aafd791cfb6b34399f7befe969e03a7d | |
parent | bd2251939c7e4c9903aa3a6eb838f489b0328bcd (diff) |
Wrote producer relation editor interface
Again, mostly copied from the VN relation editor...
-rw-r--r-- | data/lang.txt | 48 | ||||
-rw-r--r-- | data/script.js | 115 | ||||
-rw-r--r-- | data/style.css | 10 | ||||
-rw-r--r-- | lib/VNDB/Handler/Producers.pm | 30 | ||||
-rwxr-xr-x | util/jsgen.pl | 3 |
5 files changed, 203 insertions, 3 deletions
diff --git a/data/lang.txt b/data/lang.txt index 9d7bf027..df894718 100644 --- a/data/lang.txt +++ b/data/lang.txt @@ -2296,6 +2296,54 @@ ru*: cs*: hu*: +:_pedit_rel_sel +en : Selected producers +ru*: +cs*: +hu*: + +:_pedit_rel_add +en : Add producer +ru*: +cs*: +hu*: + +:_pedit_rel_addbut +en : add +ru*: +cs*: +hu*: + +:_pedit_rel_del +en : remove +ru*: +cs*: +hu*: + +:_pedit_rel_none +en : Nothing selected. +ru*: +cs*: +hu*: + +:_pedit_rel_findformat +en : Producer textbox should start with an ID (e.g. "p7:") +ru*: +cs*: +hu*: + +:_pedit_rel_notfound +en : Producer not found +ru*: +cs*: +hu*: + +:_pedit_rel_double +en : Producer already selected! +ru*: +cs*: +hu*: + # Browse/search producers diff --git a/data/script.js b/data/script.js index a6600f9f..8ab9b003 100644 --- a/data/script.js +++ b/data/script.js @@ -5,6 +5,7 @@ * iv -> image viewer * jt -> Javascript Tabs * med -> Release media selector + * prr -> Producer relation editor * rl -> Release List dropdown * rpr -> Release <-> producer linking * rvn -> Release <-> visual novel linking @@ -1533,6 +1534,120 @@ if(byId('jt_box_rel_prod')) +/* P R O D U C E R R E L A T I O N S (/p+/edit) */ + +function prrLoad() { + // read the current relations + var rels = byId('prodrelations').value.split('|||'); + for(var i=0; i<rels.length && rels[0].length>1; i++) { + var rel = rels[i].split(',', 3); + prrAdd(rel[0], rel[1], rel[2]); + } + prrEmpty(); + + // bind the add-link + byName(byClass(byId('relation_new'), 'td', 'tc_add')[0], 'a')[0].onclick = prrFormAdd; + + // dropdown + dsInit(byName(byClass(byId('relation_new'), 'td', 'tc_prod')[0], 'input')[0], '/xml/producers.xml?q=', function(item, tr) { + tr.appendChild(tag('td', { style: 'text-align: right; padding-right: 5px'}, 'p'+item.getAttribute('id'))); + tr.appendChild(tag('td', shorten(item.firstChild.nodeValue, 40))); + }, function(item) { + return 'p'+item.getAttribute('id')+':'+item.firstChild.nodeValue; + }, prrFormAdd); +} + +function prrAdd(rel, pid, title) { + var sel = tag('select', {onchange: prrSerialize}); + var ops = byName(byClass(byId('relation_new'), 'td', 'tc_rel')[0], 'select')[0].options; + for(var i=0; i<ops.length; i++) + sel.appendChild(tag('option', {value: ops[i].value, selected: ops[i].value==rel}, getText(ops[i]))); + + byId('relation_tbl').appendChild(tag('tr', {id:'relation_tr_'+pid}, + tag('td', {'class':'tc_prod' }, 'p'+pid+':', tag('a', {href:'/p'+pid}, shorten(title, 40))), + tag('td', {'class':'tc_rel' }, sel), + tag('td', {'class':'tc_add' }, tag('a', {href:'#', onclick:prrDel}, mt('_pedit_rel_del'))) + )); + + prrEmpty(); +} + +function prrEmpty() { + var tbl = byId('relation_tbl'); + if(byName(tbl, 'tr').length < 1) + tbl.appendChild(tag('tr', {id:'relation_tr_none'}, tag('td', {colspan:4}, mt('_pedit_rel_none')))); + else if(byId('relation_tr_none')) + tbl.removeChild(byId('relation_tr_none')); +} + +function prrSerialize() { + var r = []; + var trs = byName(byId('relation_tbl'), 'tr'); + for(var i=0; i<trs.length; i++) { + if(trs[i].id == 'relation_tr_none') + continue; + var rel = byName(byClass(trs[i], 'td', 'tc_rel')[0], 'select')[0]; + r[r.length] = [ + rel.options[rel.selectedIndex].value, + trs[i].id.substr(12), + getText(byName(byClass(trs[i], 'td', 'tc_prod')[0], 'a')[0]) + ].join(','); + } + byId('prodrelations').value = r.join('|||'); +} + +function prrDel() { + var tr = this; + while(tr.nodeName.toLowerCase() != 'tr') + tr = tr.parentNode; + byId('relation_tbl').removeChild(tr); + prrSerialize(); + prrEmpty(); + return false; +} + +function prrFormAdd() { + var relnew = byId('relation_new'); + var txt = byName(byClass(relnew, 'td', 'tc_prod')[0], 'input')[0]; + var sel = byName(byClass(relnew, 'td', 'tc_rel')[0], 'select')[0]; + var lnk = byName(byClass(relnew, 'td', 'tc_add')[0], 'a')[0]; + var input = txt.value; + + if(!input.match(/^p[0-9]+/)) { + alert('_pedit_rel_findformat'); + return false; + } + + txt.disabled = sel.disabled = true; + txt.value = mt('_js_loading'); + setText(lnk, mt('_js_loading')); + + ajax('/xml/producers.xml?q='+encodeURIComponent(input), function(hr) { + txt.disabled = sel.disabled = false; + txt.value = ''; + setText(lnk, mt('_pedit_rel_addbut')); + + var items = hr.responseXML.getElementsByTagName('item'); + if(items.length < 1) + return alert(mt('_pedit_rel_notfound')); + + var id = items[0].getAttribute('id'); + if(byId('relation_tr_'+id)) + return alert(mt('_pedit_rel_double')); + + prrAdd(sel.selectedIndex, id, items[0].firstChild.nodeValue); + sel.selectedIndex = 0; + prrSerialize(); + }); + return false; +} + +if(byId('prodrelations')) + prrLoad(); + + + + /* M I S C S T U F F */ // search box diff --git a/data/style.css b/data/style.css index bec0686a..ea793578 100644 --- a/data/style.css +++ b/data/style.css @@ -844,6 +844,16 @@ div.scr_uploader { visibility: hidden; overflow: hidden; width: 1px; height: 1px padding-bottom: 10px!important } +/***** Producer edit *****/ + +#jt_box_pedit_rel table { margin-bottom: 10px; } +#jt_box_pedit_rel h2 { margin: 0 0 3px 0px; } +#jt_box_pedit_rel td { padding: 1px 2px; vertical-align: middle; } +#jt_box_pedit_rel td.tc_prod { width: 290px; padding-left: 10px } +#jt_box_pedit_rel td.tc_add { width: 40px; text-align: left } +#jt_box_pedit_rel td.tc_prod input { width: 280px; } +#jt_box_pedit_rel td.tc_rel select { width: 130px; } + diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm index f662ba3e..41465b18 100644 --- a/lib/VNDB/Handler/Producers.pm +++ b/lib/VNDB/Handler/Producers.pm @@ -69,7 +69,7 @@ sub page { p class => 'center'; txt "\n"; for my $r (sort keys %rel) { - txt mt("_prodrel_$r").' '; + txt mt("_prodrel_$r").': '; for (@{$rel{$r}}) { a href => "/p$_->{id}", title => $_->{original}||$_->{name}, shorten $_->{name}, 40; txt ', ' if $_ ne $rel{$r}[$#{$rel{$r}}]; @@ -191,7 +191,33 @@ sub edit { [ input => name => mt('_pedit_form_website'), short => 'website' ], [ text => name => mt('_pedit_form_desc').'<br /><b class="standout">'.mt('_inenglish').'</b>', short => 'desc', rows => 6 ], ], 'pedit_rel' => [ mt('_pedit_form_rel'), - [ textarea => short => 'prodrelations' ], + [ hidden => short => 'prodrelations' ], + [ static => nolabel => 1, content => sub { + h2 mt '_pedit_rel_sel'; + table; + tbody id => 'relation_tbl'; + # to be filled using javascript + end; + end; + + h2 mt '_pedit_rel_add'; + table; + Tr id => 'relation_new'; + td class => 'tc_prod'; + input type => 'text', class => 'text'; + end; + td class => 'tc_rel'; + Select; + option value => $_, mt "_prodrel_$_" + for (sort { $self->{prod_relations}{$a}[0] <=> $self->{prod_relations}{$b}[0] } keys %{$self->{prod_relations}}); + end; + end; + td class => 'tc_add'; + a href => '#', mt '_pedit_rel_addbut'; + end; + end; + end; + }], ]); $self->htmlFooter; } diff --git a/util/jsgen.pl b/util/jsgen.pl index 56897679..1ad8fb53 100755 --- a/util/jsgen.pl +++ b/util/jsgen.pl @@ -34,7 +34,8 @@ my $jskeys = qr{^(?: _vnedit_scr_.+| _tagv_(?:add|spoil\d|notfound|nometa|double)| _redit_form_vn_(?:addbut|remove|none|vnformat|notfound|double)| - _redit_form_prod_(?:addbut|remove|none|pformat|notfound|double) + _redit_form_prod_(?:addbut|remove|none|pformat|notfound|double)| + _pedit_rel_(?:addbut|del|none|findformat|notfound|double) )$}x; sub l10n { |