summaryrefslogtreecommitdiff
path: root/find.php
diff options
context:
space:
mode:
authorŁukasz Wilenski <wooc@gazeta.pl>2010-05-13 21:51:23 +0000
committerŁukasz Wilenski <wooc@gazeta.pl>2010-05-13 21:51:23 +0000
commit698b4f9cc773f080afbea12c31091ec3df7cfc72 (patch)
tree1f43e8ffb183115a6567b17b6d7b959229d59639 /find.php
parent463a0f978c348c874c65bff73ace132ca5b19a1b (diff)
downloadwebtrees-698b4f9cc773f080afbea12c31091ec3df7cfc72.tar.gz
webtrees-698b4f9cc773f080afbea12c31091ec3df7cfc72.tar.bz2
webtrees-698b4f9cc773f080afbea12c31091ec3df7cfc72.zip
Choosing a GEDCOM tag from a list (mlocati)
Diffstat (limited to 'find.php')
-rw-r--r--find.php245
1 files changed, 245 insertions, 0 deletions
diff --git a/find.php b/find.php
index 619552b951..bd0fdb3edf 100644
--- a/find.php
+++ b/find.php
@@ -47,6 +47,26 @@ $choose =safe_GET('choose', WT_REGEX_NOSCRIPT, '0all');
$level =safe_GET('level', WT_REGEX_INTEGER, 0);
$language_filter=safe_GET('language_filter');
$magnify =safe_GET_bool('magnify');
+$qs =safe_GET('tags');
+
+
+
+// Retrives the currently selected tags in the opener window (reading curTags value of the query string)
+// $preselDefault will be set to the array of DEFAULT preselected tags
+// $preselCustom will be set to the array of CUSTOM preselected tags
+function getPreselectedTags(&$preselDefault, &$preselCustom) {
+ global $FACTS, $qs;
+ $all = strlen($qs) ? explode(',', strtoupper($qs)) : array();
+ $preselDefault = array();
+ $preselCustom = array();
+ foreach($all as $one) {
+ if(array_key_exists($one, $FACTS)) {
+ $preselDefault[] = $one;
+ } else {
+ $preselCustom[] = $one;
+ }
+ }
+}
if ($showthumb) {
$thumbget='&showthumb=true';
@@ -123,6 +143,10 @@ case "specialchar":
print_simple_header(i18n::translate('Find Special Characters'));
$action="filter";
break;
+case "facts":
+ $ONLOADFUNCTION = 'initPickFact();';
+ print_simple_header(i18n::translate('Find fact tags'));
+ break;
}
echo WT_JS_START;
@@ -184,6 +208,7 @@ $options["option"][]= "findrepo";
$options["option"][]= "findnote";
$options["option"][]= "findsource";
$options["option"][]= "findspecialchar";
+$options["option"][]= "findfact";
$options["form"][]= "formindi";
$options["form"][]= "formfam";
$options["form"][]= "formmedia";
@@ -222,6 +247,9 @@ case "source":
case "specialchar":
echo i18n::translate('Find Special Characters');
break;
+case "facts":
+ echo i18n::translate('Find fact tags');
+ break;
}
echo "</td>"; // close column for find text header
@@ -407,6 +435,223 @@ if ($type == "specialchar") {
echo "</td></tr></table>";
echo "</form></div>";
}
+
+// Show facts
+if ($type == "facts") {
+ echo "<div align=\"center\">";
+ echo "<form name=\"filterfacts\" method=\"get\" action=\"find.php\" >";
+ echo "<input type=\"hidden\" name=\"type\" value=\"facts\" />";
+ echo "<input type=\"hidden\" name=\"tags\" value=\"$qs\" />";
+ echo "<input type=\"hidden\" name=\"callback\" value=\"$callback\" />";
+ echo "<table class=\"list_table $TEXT_DIRECTION width100\" border=\"0\">";
+ echo "<tr><td class=\"list_label $TEXT_DIRECTION\" style=\"padding: 5px; font-weight: normal; white-space: normal;\">";
+ getPreselectedTags($preselDefault, $preselCustom);
+ ?>
+ <style type="text/css">
+ #layDefinedTags { width:450px; }
+ #tabDefinedTags { width:430px; }
+ #layDefinedTags
+ {
+ margin-left:auto;
+ margin-right:auto;
+ height:300px;
+ overflow:auto;
+ border:inset 2px buttonface;
+ }
+ #tabDefinedTags
+ {
+ border-collapse:collapse;
+ }
+ #tabDefinedTags th,#tabDefinedTags td
+ {
+ border:solid 1px #000;
+ margin:0;
+ padding:3px;
+ }
+ #tabDefinedTags tbody th
+ {
+ text-align:left;
+ font-weight:bold;
+ }
+ #tabDefinedTags tr.sel
+ {
+ background-color:#efe;
+ }
+ #tabDefinedTags tr.unsel
+ {
+ background-color:#fee;
+ }
+ #tabFilterAndCustom
+ {
+ margin-left:auto;
+ margin-right:auto;
+ }
+ #tabAction
+ {
+ margin-left:auto;
+ margin-right:auto;
+ }
+ #tabAction td
+ {
+ width:50%;
+ text-align:center;
+ }
+ </style>
+ <?php echo WT_JS_START; ?>
+ // A class representing a default tag
+ function DefaultTag(id, name, selected) {
+ this.Id=id;
+ this.Name=name;
+ this.LowerName=name.toLowerCase();
+ this._counter=DefaultTag.prototype._newCounter++;
+ this.selected=!!selected;
+ }
+ DefaultTag.prototype= {
+ _newCounter:0
+ ,view:function() {
+ var row=document.createElement("tr"),cell,o;
+ row.appendChild(cell=document.createElement("td"));
+ o=null;
+ if(document.all) {
+ //Old IEs handle the creation of a checkbox already checked, as far as I know, only in this way
+ try {
+ o=document.createElement("<input type='checkbox' id='tag"+this._counter+"' "+(this.selected?"checked='checked'":"")+" />");
+ } catch(e) {
+ o=null;
+ }
+ }
+ if(!o) {
+ o=document.createElement("input");
+ o.setAttribute("id","tag"+this._counter);
+ o.setAttribute("type","checkbox");
+ if(this.selected) o.setAttribute("checked", "checked");
+ }
+ o.DefaultTag=this;
+ o.ParentRow=row;
+ o.onclick=function() {
+ this.DefaultTag.selected=!!this.checked;
+ this.ParentRow.className=this.DefaultTag.selected?"sel":"unsel";
+ };
+ cell.appendChild(o);
+ row.appendChild(cell=document.createElement("th"));
+ cell.appendChild(o=document.createElement("label"));
+ o.htmlFor="tag"+this._counter;
+ o.appendChild(document.createTextNode(this.Id));
+ row.appendChild(cell=document.createElement("td"));
+ cell.appendChild(document.createTextNode(this.Name));
+ TheList.appendChild(row);
+ row.className=this.selected?"sel":"unsel";
+ }
+ };
+ // Some global variable
+ var DefaultTags=null /*The list of the default tag*/, TheList=null /* The body of the table that will show the default tabs */;
+
+ // A single-instance class that manage the populating of the table
+ var Lister= {
+ _curFilter:null
+ ,_timer:null
+ ,clear:function() {
+ var n=TheList.childNodes.length;
+ while(n) TheList.removeChild(TheList.childNodes[--n]);
+ }
+ ,_clearTimer:function() {
+ if(this._timer!=null) {
+ clearTimeout(this._timer);
+ this._timer=null;
+ }
+ }
+ ,askRefresh:function() {
+ this._clearTimer();
+ this._timer=setTimeout("Lister.refreshNow()",200);
+ }
+ ,refreshNow:function() {
+ this._clearTimer();
+ var s=document.getElementById("tbxFilter").value.toLowerCase().replace(/\s+/g," ").replace(/^ | $/g,""),k;
+ if((typeof(this._curFilter)!="string")||(this._curFilter!=s)) {
+ this._curFilter=s;
+ this.clear();
+ for(k=0;k<DefaultTags.length;k++) {
+ if(DefaultTags[k].LowerName.indexOf(this._curFilter)>=0) DefaultTags[k].view();
+ }
+ }
+ }
+ };
+
+ function initPickFact() {
+ var n,i,j,tmp,preselectedDefaultTags="\x01<?php foreach($preselDefault as $p) echo addslashes($p), '\\x01'; ?>";
+
+ DefaultTags=[<?php
+ $firstFact=TRUE;
+ foreach($FACTS as $facId => $factName) {
+ if($firstFact) $firstFact=FALSE;
+ else echo ',';
+ echo 'new DefaultTag("'.addslashes($facId).'","'.addslashes($factName).'",preselectedDefaultTags.indexOf("\\x01'.addslashes($facId).'\\x01")>=0)';
+ }
+ ?>];
+ //Sort defined tags alphabetically by name
+ n=DefaultTags.length
+ for(i=0;i<(n-1);i++) {
+ for(j=(i+1);j<n;j++) {
+ if(DefaultTags[i].LowerName>DefaultTags[j].LowerName) {
+ tmp=DefaultTags[i];
+ DefaultTags[i]=DefaultTags[j];
+ DefaultTags[j]=tmp;
+ }
+ }
+ }
+ TheList=document.getElementById("tbDefinedTags");
+ i=document.getElementById("tbxFilter");
+ i.onkeypress=i.onchange=i.onkeyup=function() {
+ Lister.askRefresh();
+ };
+ Lister.refreshNow();
+ document.getElementById("btnOk").disabled=false;
+ }
+ function DoOK() {
+ var result=[],k,linearResult,custom;
+ for(k=0;k<DefaultTags.length;k++) {
+ if(DefaultTags[k].selected) result.push(DefaultTags[k].Id);
+ }
+ linearResult="\x01"+result.join("\x01")+"\x01";
+ custom=document.getElementById("tbxCustom").value.toUpperCase().replace(/\s/g,"").split(",");
+ for(k=0;k<custom.length;k++) {
+ if(linearResult.indexOf("\x01"+custom[k]+"\x01")<0) {
+ linearResult+=custom[k]+"\x01";
+ result.push(custom[k]);
+ }
+ }
+ result = result.join(",")
+ if (result.substring(result.length-1, result.length)==',') {
+ result = result.substring(0, result.length-1);
+ }
+ pasteid(result);
+ window.close();
+ return false;
+ }
+ <?php echo WT_JS_END; ?>
+ <div id="layDefinedTags"><table id="tabDefinedTags">
+ <thead><tr>
+ <th>&nbsp;</th>
+ <th><?php echo i18n::translate('Tag') ?></th>
+ <th><?php echo i18n::translate('Description') ?></th>
+ </tr></thead>
+ <tbody id="tbDefinedTags">
+ </tbody>
+ </table></div>
+
+ <table id="tabFilterAndCustom"><tbody>
+ <tr><td><?php echo i18n::translate('Filter') ?>:</td><td><input type="text" id="tbxFilter" /></td></tr>
+ <tr><td><?php echo i18n::translate('Custom tags') ?>:</td><td><input type="text" id="tbxCustom" value="<?php echo addslashes(implode(',', $preselCustom)); ?>" /></td></tr>
+ <td><td></tbody></table>
+
+ <table id="tabAction"><tbody><tr>
+ <td><button id="btnOk" disabled="disabled" onclick="if(!this.disabled)DoOK();"><?php echo i18n::translate('Accept') ?></button></td>
+ <td><button onclick="window.close();return false"><?php echo i18n::translate('Cancel') ?></button></td>
+ <tr></tbody></table>
+ <?php
+ echo "</td></tr></table>";
+ echo "</form></div>";
+}
// end column for find options
echo "</td></tr>";
echo "</table>"; // Close table with find options