1 /* advanced search interface */
3 attachEvt("common", "run", advInit);
5 function advInit() { depthSelInit(); }
7 function advWizardRun() {
8 var contains = $('advanced.wizard.contains').value;
9 var nocontains = $('advanced.wizard.nocontains').value;
10 var exact = $('advanced.wizard.exact').value;
11 var form = getSelectorVal($('advanced.wizard.form_selector'));
12 var type = getSelectorVal($('search_type_selector'));
16 arg[PARAM_FORM] = form;
17 arg[PARAM_STYPE] = type;
18 arg[PARAM_OFFSET] = 0;
19 arg[PARAM_DEPTH] = depthSelGetDepth();
20 arg[PARAM_LOCATION] = depthSelGetNewLoc();
21 arg[PARAM_TERM] = advBuildSearch( contains, nocontains, exact );
23 goTo(buildOPACLink(arg));
26 function advBuildSearch( contains, nocontains, exact ) {
28 if(contains) string = contains;
31 if(exact.indexOf('"') > -1) string += " " + exact;
32 else string += " \"" + exact + "\"";
36 var words = nocontains.split(" ");
38 string += " -" + words[i];
44 function advRefinedRun() {
45 var title = $('advanced.refined.title_contains').value;
46 var author = $('advanced.refined.author_contains').value;
47 var subject = $('advanced.refined.subject_contains').value;
48 var series = $('advanced.refined.series_contains').value;
49 var form = getSelectorVal($('advanced.refined.form_selector'));
52 title = advRefinedTerm('title', title);
53 author = advRefinedTerm('author', author);
54 subject = advRefinedTerm('subject', subject);
55 series = advRefinedTerm('series', series);
57 if(title) { blob.title = {}; blob.title.term = title; }
58 if(author) { blob.author = {}; blob.author.term = author;}
59 if(subject) { blob.subject = {}; blob.subject.term = subject;}
60 if(series) { blob.series = {}; blob.series.term = series; }
64 arg[PARAM_FORM] = form;
65 arg[PARAM_STYPE] = "";
67 arg[PARAM_ADVTERM] = js2JSON(blob);
68 arg[PARAM_DEPTH] = depthSelGetDepth();
69 arg[PARAM_LOCATION] = depthSelGetNewLoc();
70 arg[PARAM_OFFSET] = 0;
71 arg[PARAM_ADVTYPE] = ADVTYPE_MULTI;
73 goTo(buildOPACLink(arg));
77 function advISBNRun() {
78 var isbn = $('opac.advanced.quick.isbn').value;
82 arg[PARAM_STYPE] = "";
84 arg[PARAM_ADVTERM] = isbn;
85 arg[PARAM_OFFSET] = 0;
86 arg[PARAM_ADVTYPE] = ADVTYPE_ISBN;
87 goTo(buildOPACLink(arg));
90 function advISSNRun() {
91 var issn = $('opac.advanced.quick.issn').value;
95 arg[PARAM_STYPE] = "";
97 arg[PARAM_ADVTERM] = issn;
98 arg[PARAM_OFFSET] = 0;
99 arg[PARAM_ADVTYPE] = ADVTYPE_ISSN;
100 goTo(buildOPACLink(arg));
104 function advRefinedTerm( type, term ) {
105 var t = getSelectorVal($('advanced.refined.' + type + '_type'));
108 if( t == 'contains' ) string = advBuildSearch( term );
109 else if( t == 'nocontains' ) string = advBuildSearch( null, term );
110 else if( t == 'exact' ) string = advBuildSearch( null, null, term );
116 function advAddMARC() {
117 $('advanced.marc.tbody').insertBefore(
118 $('advanced.marc.template').cloneNode(true),
119 $('advanced.marc.submit.row'));
122 function advMARCRun() {
124 var t = $('advanced.marc.tbody');
127 for( var c in t.childNodes ) {
128 var child = t.childNodes[c];
129 if(child.nodeName == 'tr') {
131 var val = advExtractMARC(child);
132 if(val) searches.push(val);
137 var children = t.getElementsByTagName('tr');
138 for( var c in children ) {
139 var child = children[c];
140 if(!(child && child.innerHTML)) continue;
141 var val = advExtractMARC(child);
142 if(val) searches.push(val);
145 if(searches.length == 0) return;
149 arg[PARAM_FORM] = 'all'
150 arg[PARAM_STYPE] = "";
151 arg[PARAM_OFFSET] = 0;
152 arg[PARAM_DEPTH] = depthSelGetDepth();
153 arg[PARAM_LOCATION] = depthSelGetNewLoc();
154 arg[PARAM_ADVTERM] = js2JSON(searches);
155 arg[PARAM_ADVTYPE] = ADVTYPE_MARC;
156 arg[PARAM_TERM] = "";
158 goTo(buildOPACLink(arg));
162 /* EXAMPLE => {"term":"0516011901","restrict":[{"tag":"020","subfield":"a"}]} */
163 function advExtractMARC(row) {
164 if(!row || row.id == 'advanced.marc.submit.row') return null;
165 var term = $n(row, 'advanced.marc.value').value;
166 if(!term) return null;
168 var subfield = $n(row, 'advanced.marc.subfield').value;
169 if(!subfield) subfield = "_";
171 var tag = $n(row, 'advanced.marc.tag').value;
172 if(!tag) return null;
174 return { 'term' : term, 'restrict' : [ { 'tag' : tag, 'subfield' : subfield } ] };