summaryrefslogtreecommitdiff
path: root/data/js
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-07-19 10:53:48 +0200
committerYorhel <git@yorhel.nl>2020-07-19 10:55:06 +0200
commitd7767fa0f907e7b2a0a3d879d9000fa137bd81db (patch)
tree4c04045145cb43f95074a3dc03970c873ae262c4 /data/js
parent2fd1910f7f6f1218f68c404d86b25a7831725b43 (diff)
Delete old VN edit form + some other unreferenced code
There's a lot more unreferenced code in VNDB::DB::*, but I'll not spend too much effort cleaning that up right now. All of it can be deleted in bulk at some point.
Diffstat (limited to 'data/js')
-rw-r--r--data/js/iv.js138
-rw-r--r--data/js/main.js7
-rw-r--r--data/js/vncast.js112
-rw-r--r--data/js/vnrel.js124
-rw-r--r--data/js/vnscr.js206
-rw-r--r--data/js/vnstaff.js123
6 files changed, 0 insertions, 710 deletions
diff --git a/data/js/iv.js b/data/js/iv.js
deleted file mode 100644
index 98889c5e..00000000
--- a/data/js/iv.js
+++ /dev/null
@@ -1,138 +0,0 @@
-/* Simple image viewer widget. Usage:
- *
- * <a href="full_image.jpg" data-iv="{width}x{height}:{category}">..</a>
- *
- * Clicking on the above link will cause the image viewer to open
- * full_image.jpg. The {category} part can be empty or absent. If it is not
- * empty, next/previous links will show up to point to the other images within
- * the same category.
- *
- * ivInit() should be called when links with "data-iv" attributes are
- * dynamically added or removed from the DOM.
- */
-
-// Cache of image categories and the list of associated link objects. Used to
-// quickly generate the next/prev links.
-var cats;
-
-function init() {
- cats = {};
- var n = 0;
- var l = byName('a');
- for(var i=0;i<l.length;i++) {
- var o = l[i];
- if(o.getAttribute('data-iv') && o.id != 'ivprev' && o.id != 'ivnext') {
- n++;
- o.onclick = show;
- var cat = o.getAttribute('data-iv').split(':')[1];
- if(cat) {
- if(!cats[cat])
- cats[cat] = [];
- o.iv_i = cats[cat].length;
- cats[cat].push(o);
- }
- }
- }
-
- if(n && !byId('iv_view')) {
- addBody(tag('div', {id: 'iv_view','class':'hidden', onclick: function(ev) { ev.stopPropagation(); return true } },
- tag('b', {id:'ivimg'}, ''),
- tag('br', null),
- tag('a', {href:'#', id:'ivfull'}, ''),
- tag('a', {href:'#', onclick: close, id:'ivclose'}, 'close'),
- tag('a', {href:'#', onclick: show, id:'ivprev'}, '« previous'),
- tag('a', {href:'#', onclick: show, id:'ivnext'}, 'next »')
- ));
- addBody(tag('b', {id:'ivimgload','class':'hidden'}, 'Loading...'));
- }
-}
-
-// Find the next (dir=1) or previous (dir=-1) non-hidden link object for the category.
-function findnav(cat, i, dir) {
- for(var j=i+dir; j>=0 && j<cats[cat].length; j+=dir)
- if(!hasClass(cats[cat][j], 'hidden') && cats[cat][j].offsetWidth > 0 && cats[cat][j].offsetHeight > 0)
- return cats[cat][j];
- return 0
-}
-
-// fix properties of the prev/next links
-function fixnav(lnk, cat, i, dir) {
- var a = cat ? findnav(cat, i, dir) : 0;
- lnk.style.visibility = a ? 'visible' : 'hidden';
- lnk.href = a ? a.href : '#';
- lnk.iv_i = a ? a.iv_i : 0;
- lnk.setAttribute('data-iv', a ? a.getAttribute('data-iv') : '');
-}
-
-function show(ev) {
- var u = this.href;
- var opt = this.getAttribute('data-iv').split(':');
- var idx = this.iv_i;
- var view = byId('iv_view');
- var full = byId('ivfull');
-
- fixnav(byId('ivprev'), opt[1], idx, -1);
- fixnav(byId('ivnext'), opt[1], idx, 1);
-
- // calculate dimensions
- var w = Math.floor(opt[0].split('x')[0]);
- var h = Math.floor(opt[0].split('x')[1]);
- var ww = typeof(window.innerWidth) == 'number' ? window.innerWidth : document.documentElement.clientWidth;
- var wh = typeof(window.innerHeight) == 'number' ? window.innerHeight : document.documentElement.clientHeight;
- var st = typeof(window.pageYOffset) == 'number' ? window.pageYOffset : document.body && document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
- if(w+100 > ww || h+70 > wh) {
- full.href = u;
- setText(full, w+'x'+h);
- full.style.visibility = 'visible';
- if(w/h > ww/wh) { // width++
- h *= (ww-100)/w;
- w = ww-100;
- } else { // height++
- w *= (wh-70)/h;
- h = wh-70;
- }
- } else
- full.style.visibility = 'hidden';
- var dw = w;
- var dh = h+20;
- dw = dw < 200 ? 200 : dw;
-
- // update document
- setClass(view, 'hidden', false);
- setContent(byId('ivimg'), tag('img', {src:u, onclick:close,
- onload: function() { setClass(byId('ivimgload'), 'hidden', true); },
- style: 'width: '+w+'px; height: '+h+'px'
- }));
- view.style.width = dw+'px';
- view.style.height = dh+'px';
- view.style.left = ((ww - dw) / 2 - 10)+'px';
- view.style.top = ((wh - dh) / 2 + st - 20)+'px';
- byId('ivimgload').style.left = ((ww - 100) / 2 - 10)+'px';
- byId('ivimgload').style.top = ((wh - 20) / 2 + st)+'px';
- setClass(byId('ivimgload'), 'hidden', false);
-
- document.onclick = close;
- // Capture left/right arrow keys
- document.onkeydown = function(e) {
- if(e.keyCode == 37 && byId('ivprev').style.visibility == 'visible') {
- byId('ivprev').click();
- }
- if(e.keyCode == 39 && byId('ivnext').style.visibility == 'visible') {
- byId('ivnext').click();
- }
- };
- ev.stopPropagation();
- return false;
-}
-
-function close() {
- document.onclick = null;
- document.onkeydown = null;
- setClass(byId('iv_view'), 'hidden', true);
- setClass(byId('ivimgload'), 'hidden', true);
- setText(byId('ivimg'), '');
- return false;
-}
-
-window.ivInit = init;
-init();
diff --git a/data/js/main.js b/data/js/main.js
index b04b02d0..f335f1f5 100644
--- a/data/js/main.js
+++ b/data/js/main.js
@@ -28,7 +28,6 @@ VARS.resolutions = [
//include lib.js
// Reusable widgets
-//include iv.js
//include dropdown.js
//include dateselector.js
//include dropdownsearch.js
@@ -38,12 +37,6 @@ VARS.resolutions = [
//include filter.js
//include misc.js
-// VN editing (/v+/edit)
-//include vnrel.js
-//include vnscr.js
-//include vnstaff.js
-//include vncast.js
-
// Producer editing (/p+/edit)
//include prodrel.js
diff --git a/data/js/vncast.js b/data/js/vncast.js
deleted file mode 100644
index 20d7fb39..00000000
--- a/data/js/vncast.js
+++ /dev/null
@@ -1,112 +0,0 @@
-function vncLoad() {
- var cast = jsonParse(byId('seiyuu').value) || [];
- var copt = byId('cast_chars').options;
- var chars = {};
- for(var i = 0; i < copt.length; i++) {
- if(copt[i].value)
- chars[copt[i].value] = copt[i].text;
- }
- cast.sort(function(a, b) {
- if(chars[a.cid] < chars[b.cid]) return -1;
- if(chars[a.cid] > chars[b.cid]) return 1;
- return 0;
- });
- for(var i = 0; i < cast.length; i++) {
- var aid = cast[i].aid;
- if(vnsStaffData[aid]) // vnsStaffData is filled by vnsLoad()
- vncAdd(vnsStaffData[aid], cast[i].cid, cast[i].note);
- }
- vncEmpty();
-
- onSubmit(byName(byId('maincontent'), 'form')[0], vncSerialize);
-
- // dropdown search
- dsInit(byId('cast_input'), '/xml/staff.xml?q=', function(item, tr) {
- tr.appendChild(tag('td', { style: 'text-align: right; padding-right: 5px'}, 's'+item.getAttribute('sid')));
- tr.appendChild(tag('td', item.firstChild.nodeValue));
- tr.appendChild(tag('td', item.getAttribute('orig')));
- }, vncFormAdd);
-}
-
-function vncAdd(seiyuu, chr, note) {
- var tbl = byId('cast_tbl');
-
- var csel = byId('cast_chars').cloneNode(true);
- csel.removeAttribute('id');
- csel.value = chr;
-
- tbl.appendChild(tag('tr', {id:'vnc_a'+seiyuu.aid},
- tag('td', {'class':'tc_char'}, csel),
- tag('td', {'class':'tc_name'},
- tag('input', {type:'hidden', value:seiyuu.aid}),
- tag('a', {href:'/s'+seiyuu.id}, seiyuu.name)),
- tag('td', {'class':'tc_note'}, tag('input', {type:'text', 'class':'text', value:note})),
- tag('td', {'class':'tc_del'}, tag('a', {href:'#', onclick:vncDel}, 'remove'))
- ));
- vncEmpty();
- vncSerialize();
-}
-
-function vncFormAdd(item) {
- var chr = byId('cast_chars').value;
- if (chr) {
- var s = { id:item.getAttribute('sid'), aid:item.getAttribute('id'), name:item.firstChild.nodeValue };
- vncAdd(s, chr, '');
- } else
- alert('Select character first please.');
- return '';
-}
-
-function vncEmpty() {
- var x = byId('cast_loading');
- var tbody = byId('cast_tbl');
- var tbl = tbody.parentNode;
- var thead = byName(tbl, 'thead');
- if(x)
- tbody.removeChild(x);
- if(byName(tbody, 'tr').length < 1) {
- tbody.appendChild(tag('tr', {id:'cast_tr_none'},
- tag('td', {colspan:4}, 'None')));
- if (thead.length)
- tbl.removeChild(thead[0]);
- } else {
- if(byId('cast_tr_none'))
- tbody.removeChild(byId('cast_tr_none'));
- if (thead.length < 1) {
- thead = tag('thead', tag('tr',
- tag('td', {'class':'tc_char'}, 'Character'),
- tag('td', {'class':'tc_name'}, 'Seiyuu'),
- tag('td', {'class':'tc_note'}, 'Note'),
- tag('td', '')));
- tbl.insertBefore(thead, tbody);
- }
- }
-}
-
-function vncSerialize() {
- var l = byName(byId('cast_tbl'), 'tr');
- var c = [];
- for (var i = 0; i < l.length; i++) {
- if(l[i].id == 'cast_tr_none')
- continue;
- var aid = byName(byClass(l[i], 'tc_name')[0], 'input')[0];
- var role = byName(byClass(l[i], 'tc_char')[0], 'select')[0];
- var note = byName(byClass(l[i], 'tc_note')[0], 'input')[0];
- c.push({ aid:Number(aid.value), cid:Number(role.value), note:note.value });
- }
- byId('seiyuu').value = JSON.stringify(c);
- return true;
-}
-
-function vncDel() {
- var tr = this;
- while (tr.nodeName.toLowerCase() != 'tr')
- tr = tr.parentNode;
- byId('cast_tbl').removeChild(tr);
- vncEmpty();
- vncSerialize();
- return false;
-}
-
-if(byId('jt_box_vn_cast'))
- vncLoad();
diff --git a/data/js/vnrel.js b/data/js/vnrel.js
deleted file mode 100644
index 2ccb91bb..00000000
--- a/data/js/vnrel.js
+++ /dev/null
@@ -1,124 +0,0 @@
-function vnrLoad() {
- // read the current relations
- var rels = byId('vnrelations').value.split('|||');
- for(var i=0; i<rels.length && rels[0].length>1; i++) {
- var rel = rels[i].split(',');
- // fix for titles containing commas
- rel[3] = rel.splice(3).join();
- vnrAdd(rel[0], rel[1], rel[2]==1?true:false, rel[3]);
- }
- vnrEmpty();
-
- // make sure the title is up-to-date
- byId('title').onchange = function() {
- var l = byClass(byId('jt_box_vn_rel'), 'td', 'tc_title');
- for(i=0; i<l.length; i++)
- setText(l[i], shorten(this.value, 40));
- };
-
- // bind the add-link
- byName(byClass(byId('relation_new'), 'td', 'tc_add')[0], 'a')[0].onclick = vnrFormAdd;
-
- // dropdown
- dsInit(byName(byClass(byId('relation_new'), 'td', 'tc_vn')[0], 'input')[0], '/xml/vn.xml?q=', function(item, tr) {
- tr.appendChild(tag('td', { style: 'text-align: right; padding-right: 5px'}, 'v'+item.getAttribute('id')));
- tr.appendChild(tag('td', shorten(item.firstChild.nodeValue, 40)));
- }, function(item) {
- return 'v'+item.getAttribute('id')+':'+item.firstChild.nodeValue;
- }, vnrFormAdd);
-}
-
-function vnrAdd(rel, vid, official, title) {
- var sel = tag('select', {onchange: vnrSerialize});
- 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_'+vid},
- tag('td', {'class':'tc_vn' }, 'v'+vid+':', tag('a', {href:'/v'+vid}, shorten(title, 40))),
- tag('td', {'class':'tc_rel' },
- 'is an ',
- tag('input', {type: 'checkbox', onclick:vnrSerialize, id:'official_'+vid, checked:official}),
- tag('label', {'for':'official_'+vid}, 'official'),
- sel, ' of'),
- tag('td', {'class':'tc_title'}, shorten(byId('title').value, 40)),
- tag('td', {'class':'tc_add' }, tag('a', {href:'#', onclick:vnrDel}, 'remove'))
- ));
-
- vnrEmpty();
-}
-
-function vnrEmpty() {
- var tbl = byId('relation_tbl');
- if(byName(tbl, 'tr').length < 1)
- tbl.appendChild(tag('tr', {id:'relation_tr_none'}, tag('td', {colspan:4}, 'No relations selected.')));
- else if(byId('relation_tr_none'))
- tbl.removeChild(byId('relation_tr_none'));
-}
-
-function vnrSerialize() {
- 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, // relation
- trs[i].id.substr(12), // vid
- byName(byClass(trs[i], 'td', 'tc_rel')[0], 'input')[0].checked ? '1' : '0', // official
- getText(byName(byClass(trs[i], 'td', 'tc_vn')[0], 'a')[0]) // title
- ].join(',');
- }
- byId('vnrelations').value = r.join('|||');
-}
-
-function vnrDel() {
- var tr = this;
- while(tr.nodeName.toLowerCase() != 'tr')
- tr = tr.parentNode;
- byId('relation_tbl').removeChild(tr);
- vnrSerialize();
- vnrEmpty();
- return false;
-}
-
-function vnrFormAdd() {
- var relnew = byId('relation_new');
- var txt = byName(byClass(relnew, 'td', 'tc_vn')[0], 'input')[0];
- var off = byName(byClass(relnew, 'td', 'tc_rel')[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(/^v[0-9]+/)) {
- alert('Visual novel textbox must start with an ID (e.g. v17)');
- return false;
- }
-
- txt.disabled = sel.disabled = off.disabled = true;
- txt.value = 'Loading...';
- setText(lnk, 'Loading...');
-
- ajax('/xml/vn.xml?q='+encodeURIComponent(input), function(hr) {
- txt.disabled = sel.disabled = off.disabled = false;
- txt.value = '';
- setText(lnk, 'add');
-
- var items = hr.responseXML.getElementsByTagName('item');
- if(items.length < 1)
- return alert('Visual novel not found!');
-
- var id = items[0].getAttribute('id');
- if(byId('relation_tr_'+id))
- return alert('This visual novel has already been selected!');
-
- vnrAdd(sel.options[sel.selectedIndex].value, id, off.checked, items[0].firstChild.nodeValue);
- sel.selectedIndex = 0;
- vnrSerialize();
- });
- return false;
-}
-
-if(byId('vnrelations'))
- vnrLoad();
diff --git a/data/js/vnscr.js b/data/js/vnscr.js
deleted file mode 100644
index bf583e15..00000000
--- a/data/js/vnscr.js
+++ /dev/null
@@ -1,206 +0,0 @@
-var rels;
-var defRid = 0;
-var staticUrl;
-
-function init() {
- var data = jsonParse(getText(byId('screendata'))) || {};
- rels = data.rel;
- rels.unshift([ 0, '-- select release --' ]);
- staticUrl = data.staticurl;
-
- var scr = jsonParse(byId('screenshots').value) || {};
- for(i=0; i<scr.length; i++) {
- var r = scr[i];
- var s = data.size[r.id];
- loaded(add(r.nsfw, r.rid), r.id, s[0], s[1]);
- }
-
- var frm = byId('screenshots');
- while(frm.nodeName.toLowerCase() != 'form')
- frm = frm.parentNode;
- onSubmit(frm, handleSubmit);
-
- addLast();
- ivInit();
-}
-
-function handleSubmit() {
- var loading = 0;
- var norelease = 0;
-
- var r = [];
- var l = byName(byId('scr_table'), 'tr');
- for(var i=0; i<l.length-1; i++)
- if(l[i].scr_loading)
- loading = 1;
- else if(l[i].scr_rid == 0)
- norelease = 1;
- else
- r.push({ rid: l[i].scr_rid, nsfw: l[i].scr_nsfw, id: l[i].scr_id });
-
- if(loading)
- alert('Please wait for the screenshots to be uploaded before submitting the form.');
- else if(norelease)
- alert('Please select the appropriate release for every screenshot.');
- else
- byId('screenshots').value = JSON.stringify(r);
- return !loading && !norelease;
-}
-
-function genRels(sel) {
- var r = tag('select', {'class':'scr_relsel'});
- for(var i=0; i<rels.length; i++)
- r.appendChild(tag('option', {value: rels[i][0], selected: rels[i][0] == sel}, rels[i][1]));
- return r;
-}
-
-function URL(id, t) {
- return staticUrl+'/s'+t+'/'+(id%100<10?'0':'')+(id%100)+'/'+id+'.jpg';
-}
-
-// Need to run addLast() after this function
-function add(nsfw, rid) {
- var tr = tag('tr', { scr_id: 0, scr_loading: 1, scr_rid: rid, scr_nsfw: nsfw?1:0},
- tag('td', { 'class': 'thumb'}, 'Loading...'),
- tag('td',
- tag('b', 'Uploading screenshot'),
- tag('br', null),
- 'This can take a while, depending on the file size and your upload speed.',
- tag('br', null),
- tag('a', {href:'#', onclick:del}, 'cancel')
- )
- );
- byId('scr_table').appendChild(tr);
- return tr;
-}
-
-function oddDim(dim) {
- if(dim == '256x384') // special-case NDS resolution (not in the DB)
- return false;
- for(var j=0; j<VARS.resolutions.length; j++) {
- if(typeof VARS.resolutions[j][1] != 'object') {
- if(VARS.resolutions[j][0] == dim)
- return false;
- } else {
- for(var k=1; k<VARS.resolutions[j].length; k++)
- if(VARS.resolutions[j][k][1] == dim)
- return false;;
- }
- }
- return true;
-}
-
-// Need to run ivInit() after this function
-function loaded(tr, id, width, height) {
- var dim = width+'x'+height;
- tr.id = 'scr_tr_'+id;
- tr.scr_id = id;
- tr.scr_loading = 0;
-
- setContent(byName(tr, 'td')[0],
- tag('a', {href: URL(tr.scr_id, 'f'), 'data-iv':dim+':edit'},
- tag('img', {src: URL(tr.scr_id, 't')})
- )
- );
-
- var rel = genRels(tr.scr_rid);
- rel.onchange = function() { tr.scr_rid = this.options[this.selectedIndex].value };
-
- var nsfwid = 'scr_nsfw_'+id;
- setContent(byName(tr, 'td')[1],
- tag('b', 'Screenshot #'+id),
- ' (', tag('a', {href: '#', onclick:del}, 'remove'), ')',
- tag('br', null),
- 'Full size: '+dim,
- !oddDim(dim) ? null : tag('b', {'class':'standout', 'style':'font-weight: bold'},
- ' WARNING: Odd resolution! Please check whether the image has been cropped correctly.'),
- tag('br', null),
- tag('br', null),
- tag('input', {type:'checkbox', name:nsfwid, id:nsfwid, checked: tr.scr_nsfw!=0, onclick: function() { tr.scr_nsfw = this.checked?1:0 }, 'class':'scr_nsfw'}),
- tag('label', {'for':nsfwid}, 'This screenshot is NSFW'),
- tag('br', null),
- rel
- );
-}
-
-function addLast() {
- if(byId('scr_last'))
- byId('scr_table').removeChild(byId('scr_last'));
- var full = byName(byId('scr_table'), 'tr').length >= 10;
-
- var rel = genRels(defRid);
- rel.onchange = function() { defRid = this.options[this.selectedIndex].value };
- rel.id = 'scradd_relsel';
-
- byId('scr_table').appendChild(tag('tr', {id:'scr_last'},
- tag('td', {'class': 'thumb'}),
- full ? tag('td',
- tag('b', 'Enough screenshots'),
- tag('br', null),
- 'The limit of 10 screenshots per visual novel has been reached.\nIf you want to add a new screenshot, please remove an existing one first.'
- ) : tag('td',
- tag('b', 'Add screenshot'),
- tag('br', null),
- 'Image must be smaller than 5MB and in PNG or JPEG format.',
- tag('br', null),
- rel,
- tag('br', null),
- tag('input', {name:'scr_upload', id:'scr_upload', type:'file', 'class':'text', multiple:true}),
- tag('br', null),
- tag('input', {type:'button', value:'Upload!', 'class':'submit', onclick:upload})
- )
- ));
-}
-
-function del(what) {
- var tr = what && what.scr_id != null ? what : this;
- while(tr.scr_id == null)
- tr = tr.parentNode;
- if(tr.scr_ajax)
- tr.scr_ajax.abort();
- byId('scr_table').removeChild(tr);
- addLast();
- ivInit();
- return false;
-}
-
-function uploadFile(f) {
- var tr = add(0, defRid);
- var fname = f.name;
- var frm = new FormData();
- frm.append('file', f);
- tr.scr_ajax = ajax('/xml/screenshots.xml', function(hr) {
- tr.scr_ajax = null;
- var img = hr.responseXML.getElementsByTagName('image')[0];
- var id = img.getAttribute('id');
- if(id < 0) {
- alert(fname + ":\n" + (
- id == -1 ? 'Upload failed!\nOnly JPEG or PNG images are accepted.'
- : 'Upload failed!\nNo file selected, or an empty file?'));
- del(tr);
- } else {
- loaded(tr, id, img.getAttribute('width'), img.getAttribute('height'));
- ivInit();
- }
- }, true, frm);
-}
-
-function upload() {
- var files = byId('scr_upload').files;
-
- if(files.length < 1) {
- alert('Upload failed!\nNo file selected, or an empty file?');
- return false;
- } else if(files.length + byName(byId('scr_table'), 'tr').length - 1 > 10) {
- alert('Too many files selected. The total number of screenshots may not exceed 10.');
- return false;
- }
-
- for(var i=0; i<files.length; i++)
- uploadFile(files[i]);
- addLast();
- return false;
-}
-
-if(byId('jt_box_vn_scr') && byId('screenshots'))
- init();
diff --git a/data/js/vnstaff.js b/data/js/vnstaff.js
deleted file mode 100644
index 62e262e9..00000000
--- a/data/js/vnstaff.js
+++ /dev/null
@@ -1,123 +0,0 @@
-// vnsStaffData maps alias id to staff data { NNN: { id: ..., aid: NNN, name: ...} }
-// used to fill form fields instead of ajax queries in vnsLoad() and vncLoad()
-// Also used by vncast.js
-window.vnsStaffData = {};
-
-function vnsLoad() {
- window.vnsStaffData = jsonParse(getText(byId('staffdata'))) || {};
- var credits = jsonParse(byId('credits').value) || [];
- for(var i = 0; i < credits.length; i++) {
- var aid = credits[i].aid;
- if(window.vnsStaffData[aid])
- vnsAdd(window.vnsStaffData[aid], credits[i].role, credits[i].note);
- }
- vnsEmpty();
-
- onSubmit(byName(byId('maincontent'), 'form')[0], vnsCheckAndSerialize);
-
- // dropdown search
- dsInit(byId('credit_input'), '/xml/staff.xml?q=', function(item, tr) {
- tr.appendChild(tag('td', { style: 'text-align: right; padding-right: 5px'}, 's'+item.getAttribute('sid')));
- tr.appendChild(tag('td', item.firstChild.nodeValue));
- tr.appendChild(tag('td', item.getAttribute('orig')));
- }, vnsFormAdd);
-}
-
-function vnsAdd(staff, role, note) {
- var tbl = byId('credits_tbl');
-
- var rlist = tag('select', {onchange:vnsSerialize});
- var r = VARS.credit_type;
- for (var i = 0; i<r.length; i++)
- rlist.appendChild(tag('option', {value:r[i][0], selected:r[i][0]==role}, r[i][1]));
-
- tbl.appendChild(tag('tr', {id:'vns_a'+staff.aid},
- tag('td', {'class':'tc_name'},
- tag('input', {type:'hidden', value:staff.aid}),
- tag('a', {href:'/s'+staff.id}, staff.name)),
- tag('td', {'class':'tc_role'}, rlist),
- tag('td', {'class':'tc_note'}, tag('input', {type:'text', 'class':'text', value:note})),
- tag('td', {'class':'tc_del'}, tag('a', {href:'#', onclick:vnsDel}, 'remove'))
- ));
- vnsEmpty();
- vnsSerialize();
-}
-
-function vnsEmpty() {
- var x = byId('credits_loading');
- var tbody = byId('credits_tbl');
- var tbl = tbody.parentNode;
- var thead = byName(tbl, 'thead');
- if(x)
- tbody.removeChild(x);
- if(byName(tbody, 'tr').length < 1) {
- tbody.appendChild(tag('tr', {id:'credits_tr_none'},
- tag('td', {colspan:4}, 'None')));
- if (thead.length)
- tbl.removeChild(thead[0]);
- } else {
- if(byId('credits_tr_none'))
- tbody.removeChild(byId('credits_tr_none'));
- if (thead.length < 1) {
- thead = tag('thead', tag('tr',
- tag('td', {'class':'tc_name'}, 'Staff'),
- tag('td', {'class':'tc_role'}, 'Credit'),
- tag('td', {'class':'tc_note'}, 'Note'),
- tag('td', '')));
- tbl.insertBefore(thead, tbody);
- }
- }
-}
-
-function vnsSerialize() {
- var l = byName(byId('credits_tbl'), 'tr');
- var c = [];
- for (var i = 0; i < l.length; i++) {
- if(l[i].id == 'credits_tr_none')
- continue;
- var aid = byName(byClass(l[i], 'tc_name')[0], 'input')[0];
- var role = byName(byClass(l[i], 'tc_role')[0], 'select')[0];
- var note = byName(byClass(l[i], 'tc_note')[0], 'input')[0];
- c.push({ aid:Number(aid.value), role:role.value, note:note.value });
- }
- byId('credits').value = JSON.stringify(c);
- return true;
-}
-
-function vnsCheckAndSerialize() {
- var l = byName(byId('credits_tbl'), 'tr');
- var tbl = {};
- for (var i = 0; i < l.length; i++) {
- if(l[i].id == 'credits_tr_none')
- continue;
- var aid = byName(byClass(l[i], 'tc_name')[0], 'input')[0];
- var name = byName(byClass(l[i], 'tc_name')[0], 'a')[0];
- var role = byName(byClass(l[i], 'tc_role')[0], 'select')[0];
- var idx = aid.value + ' ' + role.value;
- if(tbl[idx]) {
- alert("Invalid input in staff listing: '" + name.innerText + "' is credited multiple times with '" + role.options[role.selectedIndex].value + "'.");
- return false;
- }
- tbl[idx] = 1;
- }
- return vnsSerialize();
-}
-
-function vnsDel() {
- var tr = this;
- while (tr.nodeName.toLowerCase() != 'tr')
- tr = tr.parentNode;
- byId('credits_tbl').removeChild(tr);
- vnsEmpty();
- vnsSerialize();
- return false;
-}
-
-function vnsFormAdd(item) {
- var s = { id:item.getAttribute('sid'), aid:item.getAttribute('id'), name:item.firstChild.nodeValue };
- vnsAdd(s, 'staff', '');
- return '';
-}
-
-if(byId('jt_box_vn_staff'))
- vnsLoad();