|
| 1 | +// This code was in the CMS DocDB but was preventing the author fields from being pre-filled. It was removed as it doesn't |
| 2 | +// seem to provide real value. Originally written by Vidmantis |
| 3 | + |
| 4 | + |
| 5 | + var docDB_temp_hacks = 0; |
| 6 | + |
| 7 | + |
| 8 | + function extended_author_search(){ |
| 9 | + jQuery.extend(jQuery.expr[':'], { |
| 10 | + 'containsi': function(elem, i, match, array) |
| 11 | + { |
| 12 | + return (elem.textContent || elem.innerText || '').toLowerCase() |
| 13 | + .indexOf((match[3] || "").toLowerCase()) >= 0; |
| 14 | + } |
| 15 | + }); |
| 16 | + jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/; |
| 17 | + while(x<c.length){var m=r.exec(c.substr(x)); |
| 18 | + if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length; |
| 19 | + }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16); |
| 20 | + o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;}, |
| 21 | + URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/; |
| 22 | + while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16); |
| 23 | + t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;} |
| 24 | + }); |
| 25 | + |
| 26 | + |
| 27 | + // extract url parameter |
| 28 | + jQuery.extend({ |
| 29 | + getUrlVars: function(){ |
| 30 | + var vars = [], hash; |
| 31 | + var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); |
| 32 | + for(var i = 0; i < hashes.length; i++) |
| 33 | + { |
| 34 | + hash = hashes[i].split('='); |
| 35 | + vars.push(hash[0]); |
| 36 | + vars[hash[0]] = hash[1]; |
| 37 | + } |
| 38 | + return vars; |
| 39 | + }, |
| 40 | + getUrlVar: function(name){ |
| 41 | + return jQuery.getUrlVars()[name]; |
| 42 | + } |
| 43 | + }); |
| 44 | + |
| 45 | + var author_search = jQuery.getUrlVar('author'); |
| 46 | + |
| 47 | + |
| 48 | + if (author_search){ |
| 49 | + jQuery('h3').html(jQuery('<a href="#">show all authors</a>').click(function(){jQuery('table tr td ul li, table tr td a, table tr th').show(); })).show(); |
| 50 | + |
| 51 | + |
| 52 | + jQuery('table tr td ul li, table tr td a, table tr th').hide(); |
| 53 | + |
| 54 | + params = author_search.replace('.', ' ').replace('+', ' ').replace(',', ' ').split(' ') |
| 55 | + |
| 56 | + filtered = jQuery('table tr td ul li a') |
| 57 | + |
| 58 | + jQuery(params).each(function(i, param){ |
| 59 | + //TODO: handle special chars and international names |
| 60 | + //console.log(param); |
| 61 | + |
| 62 | + //clean up the string, leave only letters |
| 63 | + param = param.replace(/[^a-zA-Z]/g, ''); |
| 64 | + if (!param) |
| 65 | + return; |
| 66 | + |
| 67 | + filtered = filtered.filter(':containsi('+param+')'); |
| 68 | + }); |
| 69 | + items = filtered.show().parent().show().addClass('search_matched') |
| 70 | + |
| 71 | + |
| 72 | + //console.log(items) |
| 73 | + |
| 74 | + /* If there was only one result, point to the documents by the author */ |
| 75 | + if (items.length == 1){ |
| 76 | + var target = items.find("a").first().attr('href'); |
| 77 | + //console.log("Blah:"+target); |
| 78 | + location.href = target; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + function apply_cms_styles(){ |
| 86 | + /* watermark the search */ |
| 87 | + var searchField = jQuery('div#header-search-container input[type=text][name=simpletext]'); |
| 88 | + /* we take the value of watermark from title attribute */ |
| 89 | + searchField.watermark(searchField.attr('title'), {className: 'watermark-search'}); |
| 90 | + |
| 91 | + jQuery('div#header-search-container form').submit(function(e){ |
| 92 | + //check if value has an ID |
| 93 | + var value =jQuery('input#header-search-input').val(); |
| 94 | + //alert(value); |
| 95 | + var regexp = /id:(\\d+)/i; |
| 96 | + if (regexp.test(value)){ |
| 97 | + //alert('ID'); |
| 98 | + e.preventDefault(); |
| 99 | + value.match(regexp); |
| 100 | + docid = RegExp.\$1; |
| 101 | + window.location.href = 'ShowDocument?docid=' + docid |
| 102 | + } |
| 103 | + }); |
| 104 | + |
| 105 | + |
| 106 | + /* hide keywords */ |
| 107 | + if (jQuery('form#documentadd input[name=keywords]')) { |
| 108 | + jQuery('form#documentadd input[name=keywords]').parents("tr").first().hide(); |
| 109 | + } |
| 110 | + |
| 111 | + /* fix styles */ |
| 112 | + for (i=1; i<1000; i=i+2){ |
| 113 | + if (!jQuery('input[name=upload'+i+']')) |
| 114 | + break; |
| 115 | + jQuery('input[name=upload'+i+']').parents('tr').first().addClass('FileUpload'); |
| 116 | + jQuery('input[name=filedesc'+i+']').parents('tr').first().addClass('FileUpload'); |
| 117 | + jQuery('input[name=fileid'+i+']').parents('tr').first().addClass('FileUpload'); |
| 118 | + } |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + if (docDB_temp_hacks){ |
| 124 | + /* TODO: (temporaly) set up file input coloring */ |
| 125 | + for (i=1; i<1000; i=i+2){ |
| 126 | + if (!jQuery('input[name=upload'+i+']')) |
| 127 | + break; |
| 128 | + jQuery('input[name=upload'+i+']').parents('tr').first().addClass('file-upload-row-odd'); |
| 129 | + jQuery('input[name=filedesc'+i+']').parents('tr').first().addClass('file-upload-row-odd'); |
| 130 | + jQuery('input[name=fileid'+i+']').parents('tr').first().addClass('file-upload-row-odd'); |
| 131 | + } |
| 132 | + |
| 133 | + /* add select all button */ |
| 134 | + if (jQuery('form#documentadd input[name=copyfile1]')){ |
| 135 | + jQuery('form#documentadd input[name=copyfile1]').parents("td").first().append(' <a>copy all files<a>').toggle(function(evt){evt.preventDefault();jQuery('[name^="copyfile"]').val(["on"])}, function(evt){evt.preventDefault();jQuery('[name^="copyfile"]').val([""])}) |
| 136 | + } |
| 137 | + |
| 138 | + } |
| 139 | + |
| 140 | + |
| 141 | + } |
| 142 | + |
| 143 | + /* ========== set up the validation =========== */ |
| 144 | + function form_add_validation(){ |
| 145 | + |
| 146 | + jQuery.validator.messages.required = ""; |
| 147 | + |
| 148 | + /* pre-validate the form */ |
| 149 | + jQuery("form#documentadd").validate({onfocusout: true, onkeyup: true}); |
| 150 | + } |
| 151 | + |
| 152 | + |
| 153 | + if (!(typeof jQuery === 'undefined') && !(typeof jQuery.validator === 'undefined')){ |
| 154 | + jQuery(document).ready(function() { |
| 155 | + /* Here we could customize the validation (again) */ |
| 156 | + form_add_validation(); |
| 157 | + }); |
| 158 | + } |
| 159 | + |
| 160 | + if (!(typeof jQuery === 'undefined')){ |
| 161 | + jQuery(document).ready(function() { |
| 162 | + apply_cms_styles(); |
| 163 | + extended_author_search(); |
| 164 | + if (jQuery('form#documentadd select[name=security]').length == 1) { CmsTransformPermissions(); } |
| 165 | + }); |
| 166 | + } |
| 167 | + |
| 168 | + |
0 commit comments