From bad759e90cae690cc4ccb36aa388d8157f5aeb4a Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sun, 4 Oct 2009 10:08:52 +0200 Subject: JS: Moved and rewrote VN relations editor + Some fixes and improvements in the dropdown search + Renamed 'relations' field to 'vnrelations', as other relations are going to be implemented as well New relation editor code is somewhat smaller than the old, mostly thanks to the tag() function. Also tried to make things less error-prone and easier to maintain by referencing things using self-explainable class names instead of the ordering of the HTML tags. --- static/f/forms.js | 166 ----------------------------------------------------- static/f/script.js | 130 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 128 insertions(+), 168 deletions(-) (limited to 'static') diff --git a/static/f/forms.js b/static/f/forms.js index 57513735..cf03ebc4 100644 --- a/static/f/forms.js +++ b/static/f/forms.js @@ -1,170 +1,6 @@ function qq(v) { return v.replace(/&/g,"&").replace(//,">").replace(/"/g,'"'); } -function shorten(v, l) { - return qq(v.length > l ? v.substr(0, l-3)+'...' : v); -} - - - - - /*****************************\ - * V N R E L A T I O N S * - \*****************************/ - - -var relTypes = []; -function relLoad() { - var i;var l;var o; - - // fetch the relation types from the add new relation selectbox - l = x('relation_new').getElementsByTagName('select')[0].options; - for(i=0;i'+shorten(title, 40)+''; - o.appendChild(t); - - var options = ''; - for(var i in relTypes) - options += ''; - t = document.createElement('td'); - t.className = 'tc2'; - t.innerHTML = 'is a of'; - o.appendChild(t); - - t = document.createElement('td'); - t.className = 'tc3'; - t.innerHTML = shorten(x('title').value, 40); - o.appendChild(t); - - t = document.createElement('td'); - t.className = 'tc4'; - t.innerHTML = 'del'; - o.appendChild(t); - - x('relation_tbl').appendChild(o); - relEmpty(); -} - -function relEmpty() { - if(x('relation_tbl').getElementsByTagName('tr').length > 0) { - if(x('relation_tr_none')) - x('relation_tbl').removeChild(x('relation_tr_none')); - return; - } - var o = document.createElement('tr'); - o.setAttribute('id', 'relation_tr_none'); - var t = document.createElement('td'); - t.colspan = 4; - t.innerHTML = 'No relations selected.'; - o.appendChild(t); - x('relation_tbl').appendChild(o); -} - -function relSerialize() { - var r=''; - var i; - var l = x('relation_tbl').getElementsByTagName('tr'); - for(i=0;i l ? v.substr(0, l-3)+'...' : v); + return v.length > l ? v.substr(0, l-3)+'...' : v; } @@ -221,7 +221,7 @@ function ivView(what) { // update document view.style.display = 'block'; - setContent(x('ivimg'), tag('img', {src:u, onclick:ivClose, + setContent(byId('ivimg'), tag('img', {src:u, onclick:ivClose, onload: function() { byId('ivimgload').style.top='-400px'; }, style: 'width: '+w+'px; height: '+h+'px' })); @@ -547,8 +547,14 @@ function dsKeyDown(ev) { obj.value = obj.ds_serFunc(byId('ds_box_'+obj.ds_selectedId).ds_itemData, obj); if(obj.ds_returnFunc) obj.ds_returnFunc(); + byId('ds_box').style.top = '-500px'; + setContent(byId('ds_box'), tag('b', 'Loading...')); obj.ds_selectedId = 0; + if(obj.ds_dosearch) { + clearTimeout(obj.ds_dosearch); + obj.ds_dosearch = null; + } return false; } @@ -669,6 +675,126 @@ function dsResults(hr, obj) { +/* V I S U A L N O V E L R E L A T I O N S (/v+/edit) */ + +function vnrLoad() { + // read the current relations + var rels = byId('vnrelations').value.split('|||'); + for(var i=0; i