diff options
author | morkt <> | 2014-12-29 10:23:30 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2014-12-29 10:23:30 +0100 |
commit | d41b850504476132a663e6f49f80c3ff35b81739 (patch) | |
tree | d56394fd9f127d8f4bf15f5290973ed435c48bdb | |
parent | ced53e5d7ea385fe6c53ed75a20ec16b027e5c5d (diff) |
staff: Don't use inline script to pass seiyuu import data
Same reasoning as 0d191b5cd8c79eef3cef63c40ded96506a40382a
-rw-r--r-- | data/script.js | 34 | ||||
-rw-r--r-- | lib/VNDB/Handler/VNEdit.pm | 22 |
2 files changed, 29 insertions, 27 deletions
diff --git a/data/script.js b/data/script.js index d0548de1..b53e33fe 100644 --- a/data/script.js +++ b/data/script.js @@ -2055,8 +2055,8 @@ if(byId('jt_box_chare_vns')) function salLoad () { var aliases = byId('aliases').value.split('|||'); for (var i = 0; i < aliases.length && aliases[i].length > 1; i++) { - var al = aliases[i].split(',', 3); - salAdd(al[0], al[1], al[2]); + var al = aliases[i].split(','); + salAdd(al[0], al[1], al.slice(2).join(',')); } salEmpty(); @@ -2160,9 +2160,9 @@ function vnsLoad() { l[aid] = staff[i]; } for (var i = 0; i < credits.length; i++) { - var c = credits[i].split('-', 3); + var c = credits[i].split('-'); if (l[c[0]]) - vnsAdd (l[c[0]], c[1], c[2]); + vnsAdd(l[c[0]], c[1], c.slice(2).join('-')); } vnsEmpty(); }, 1); @@ -2188,13 +2188,12 @@ function vnsAdd(staff, role, note) { rlist.appendChild(tag('option', {value:staff_roles[i], selected:staff_roles[i]==role}, mt('_credit_'+staff_roles[i]))); - var note = tag('input', {type:'text', 'class':'text'}); tbl.appendChild(tag('tr', {id:'vns_a'+aid}, tag('td', {'class':'tc_name'}, tag('input', {type:'hidden', value:aid}), tag('a', {href:'/s'+sid}, staff.firstChild.nodeValue)), tag('td', {'class':'tc_role'}, rlist), - tag('td', {'class':'tc_note'}, note), + tag('td', {'class':'tc_note'}, tag('input', {type:'text', 'class':'text', value:note})), tag('td', {'class':'tc_del'}, tag('a', {href:'#', onclick:vnsDel}, mt('_js_remove'))) )); vnsEmpty(); @@ -2220,7 +2219,8 @@ function vnsEmpty() { thead = tag('thead', tag('tr', tag('td', {'class':'tc_name'}, mt('_vnstaffe_form_staff')), tag('td', {'class':'tc_role'}, mt('_vnstaffe_form_role')), - tag('td', {'class':'tc_note'}, mt('_vnstaffe_form_note')))); + tag('td', {'class':'tc_note'}, mt('_vnstaffe_form_note')), + tag('td', ''))); tbl.insertBefore(thead, tbody); } } @@ -2265,6 +2265,8 @@ if(byId('jt_box_vn_staff')) /* V N C H A R A C T E R S C A S T (/v+/edit#vn_cast) */ +var vncImportData = []; + function vncLoad() { var cast = byId('seiyuu').value.split('|||'); var q = []; // list of a=X parameters @@ -2285,18 +2287,25 @@ function vncLoad() { s[aid] = seiyuu[i]; } for (var i = 0; i < cast.length; i++) { - var c = cast[i].split('-', 3); + var c = cast[i].split('-'); if (s[c[0]]) - vncAdd(s[c[0]], c[1], c[2]); + vncAdd(s[c[0]], c[1], c.slice(2).join('-')); } vncEmpty(); }, 1); else vncEmpty(); + vncImportData = []; var cast_import = byId('cast_import'); - if (cast_import) + if (cast_import) { + var imp_data = byId('castimpdata').value.split('|||'); + for (var i = 0; i < imp_data.length; i++) { + var c = imp_data[i].split('-'); + vncImportData.push({cid:c[0],sid:c[1],aid:c[2],name:c.slice(3).join('-')}); + } byName(cast_import, 'a')[0].onclick = vncImport; + } onSubmit(byName(byId('maincontent'), 'form')[0], vncSerialize); // dropdown search @@ -2307,7 +2316,7 @@ function vncLoad() { } function vncImport() { - if (typeof vncImportData === 'undefined') + if (!vncImportData.length) return false; var c = {}; for (var i = 0; i < vncImportData.length; i++) { @@ -2343,14 +2352,13 @@ function vncAdd(seiyuu, chr, note) { var csel = byId('cast_chars').cloneNode(true); csel.removeAttribute('id'); csel.value = chr; - var note = tag('input', {type:'text', 'class':'text'}); tbl.appendChild(tag('tr', {id:'vnc_a'+aid}, tag('td', {'class':'tc_char'}, csel), tag('td', {'class':'tc_name'}, tag('input', {type:'hidden', value:aid}), tag('a', {href:'/s'+sid}, seiyuu.firstChild.nodeValue)), - tag('td', {'class':'tc_note'}, note), + tag('td', {'class':'tc_note'}, tag('input', {type:'text', 'class':'text', value:note})), tag('td', {'class':'tc_del'}, tag('a', {href:'#', onclick:vncDel}, mt('_js_remove'))) )); vncEmpty(); diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm index 963e8ce2..caf7e8a3 100644 --- a/lib/VNDB/Handler/VNEdit.pm +++ b/lib/VNDB/Handler/VNEdit.pm @@ -88,8 +88,8 @@ sub edit { my %b4 = !$vid ? () : ( (map { $_ => $v->{$_} } qw|title original desc alias length l_wp l_encubed l_renai image img_nsfw ihid ilock|), - credits => join('|||', map sprintf('%d-%s-%s', $_->{aid}, $_->{role}, $_->{note}), @{$v->{credits}}), - seiyuu => join('|||', map sprintf('%d-%d-%s', $_->{aid}, $_->{cid}, $_->{note}), @{$v->{seiyuu}}), + credits => join('|||', map join('-', $_->{aid}, $_->{role}, $_->{note}), @{$v->{credits}}), + seiyuu => join('|||', map join('-', $_->{aid}, $_->{cid}, $_->{note}), @{$v->{seiyuu}}), anime => join(' ', sort { $a <=> $b } map $_->{id}, @{$v->{anime}}), vnrelations => join('|||', map $_->{relation}.','.$_->{id}.','.($_->{official}?1:0).','.$_->{title}, sort { $a->{id} <=> $b->{id} } @{$v->{relations}}), screenshots => join(' ', map sprintf('%d,%d,%d', $_->{id}, $_->{nsfw}?1:0, $_->{rid}), @{$v->{screenshots}}), @@ -239,7 +239,8 @@ sub _uploadimage { sub _form { my($self, $v, $frm, $r) = @_; - my $chars = $v && $self->dbCharGet(vid => $v->{id}, results => 50); + my $chars = $v ? $self->dbCharGet(vid => $v->{id}, results => 50) : []; + my $import = @$chars ? $self->dbVNImportSeiyuu($v->{id}, [ map $_->{id}, @$chars ]) : []; $self->htmlForm({ frm => $frm, action => $v ? "/v$v->{id}/edit" : '/v/new', editsum => 1, upload => 1 }, vn_geninfo => [ mt('_vnedit_geninfo'), [ input => short => 'title', name => mt '_vnedit_frm_title' ], @@ -306,20 +307,13 @@ sub _form { # Cast tab is only shown for VNs with some characters listed. # There's no way to add voice actors in new VN edits since character list # would be empty anyway. - $chars && @{$chars} ? (vn_cast => [ mt('_vnedit_cast'), + @{$chars} ? (vn_cast => [ mt('_vnedit_cast'), [ hidden => short => 'seiyuu' ], + [ hidden => short => 'castimpdata', value => do { + join '|||', map join('-', $_->{cid}, $_->{sid}, $_->{aid}, $_->{name}), @$import; + }], [ static => nolabel => 1, content => sub { - my $import = $self->dbVNImportSeiyuu($v->{id}, [ map $_->{id}, @$chars ]); if (@$import) { - script type => 'text/javascript'; - lit 'var vncImportData = ['; - lit join ',', map { - my $name = $_->{name}; - $name =~ s/["\\]/\\$&/g; # escape quotes in names - sprintf('{cid:%d,sid:%d,aid:%d,name:"%s"}', $_->{cid}, $_->{sid}, $_->{aid}, $name); - } @$import; - lit '];'; - end; div id => 'cast_import'; a href => '#', title => mt('_vnedit_cast_import_title'), mt '_vnedit_cast_import'; end; |