/**
* webtrees: online genealogy
* Copyright (C) 2015 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
// "use strict";
// Specifications for various types of popup edit window.
// Choose positions to center in the smallest (1000x800) target screen
var edit_window_specs='width=650,height=600,left=175,top=100,resizable=1,scrollbars=1'; // edit_interface.php, add_media.php, gedrecord.php
var indx_window_specs='width=600,height=500,left=200,top=150,resizable=1,scrollbars=1'; // module configuration
var news_window_specs='width=740,height=650,left=200,top=150,resizable=1,scrollbars=1'; // edit_news.php
var help_window_specs='width=500,height=400,left=250,top=200,resizable=1,scrollbars=1'; // help.php
var find_window_specs='width=550,height=600,left=250,top=150,resizable=1,scrollbars=1'; // find.php, inverse_link.php
var mesg_window_specs='width=500,height=600,left=250,top=100,resizable=1,scrollbars=1'; // message.php
var chan_window_specs='width=500,height=600,left=250,top=100,resizable=1,scrollbars=1'; // edit_changes.php
var mord_window_specs='width=500,height=600,left=250,top=100,resizable=1,scrollbars=1'; // edit_interface.php, media reorder
var assist_window_specs='width=900,height=800,left=70,top=70,resizable=1,scrollbars=1'; // edit_interface.php, used for census assistant
var gmap_window_specs='width=650,height=600,left=200,top=150,resizable=1,scrollbars=1'; // googlemap module place editing
var fam_nav_specs='width=300,height=600,left=817,top=150,resizable=1,scrollbars=1'; // media_0_inverselink.php
var pastefield, nameElement, remElement; // Elements to paste to
// "rtl" on right-to-left pages.
var textDirection = jQuery('html').attr('dir');
// Create a modal dialog, fetching the contents from a URL
function modalDialog(url, title, width) {
jQuery('
')
.load(url)
.dialog({
modal: true,
width: typeof width === 'undefined' ? 700 : width,
open: function() {
// Close the window when we click outside it.
var self = this;
jQuery('.ui-widget-overlay').on('click', function () {
jQuery(self).dialog('close');
});
},
close: function() {
jQuery(this).dialog ('destroy').remove ();
}
});
return false;
}
// Get a help message.
function helpDialog(topic, module) {
jQuery.getJSON('help_text.php?help=' + topic + '&mod=' + module, function (json) {
modalNotes(json.content, json.title);
});
}
// Create a modal dialog to display notes & help
function modalNotes(content, title) {
jQuery('')
.html(content)
.dialog({
modal: true,
width: 500,
open: function() {
// Close the window when we click outside it.
var self = this;
jQuery('.ui-widget-overlay').on('click', function () {
jQuery(self).dialog('close');
});
}
});
return false;
}
function closePopupAndReloadParent(url) {
if (parent.opener) {
if (url) {
parent.opener.location = url;
} else {
parent.opener.location.reload();
}
}
window.close();
}
function expand_layer(sid) {
jQuery("#" + sid + "_img").toggleClass("icon-plus icon-minus");
jQuery('#' + sid).slideToggle("fast");
jQuery('#' + sid + '-alt').toggle(); // hide something when we show the layer - and vice-versa
return false;
}
// Open the "edit interface" popup window
function edit_interface(params, windowspecs, pastefield) {
var features = windowspecs || edit_window_specs;
window.pastefield = pastefield;
var url = 'edit_interface.php?' + jQuery.param(params) + '&ged=' + WT_GEDCOM;
window.open(url, '_blank', features);
return false;
}
function edit_record(xref, fact_id) {
return edit_interface({
"action": "edit",
"xref": xref,
"fact_id": fact_id
});
}
function add_fact(xref, fact) {
return edit_interface({
"action": "add",
"xref": xref,
"fact": fact
});
}
function edit_raw(xref) {
return edit_interface({
"action": "editraw",
"xref": xref
});
}
function edit_note(xref) {
return edit_interface({
"action": "editnote",
"xref": xref
});
}
function add_record(xref, fact_field) {
var fact = jQuery('#' + fact_field).val();
if (fact) {
if (fact === "OBJE") {
window.open('addmedia.php?action=showmediaform&linkid=' + encodeURIComponent(xref) + '&ged=' + encodeURIComponent(WT_GEDCOM), '_blank', edit_window_specs);
} else {
return add_fact(xref, fact);
}
}
return false;
}
function reorder_media(xref) {
return edit_interface({
"action": "reorder_media",
"xref": xref
}, mord_window_specs);
}
function add_new_record(xref, fact) {
return edit_interface({
"action": "add",
"xref": xref,
"fact": fact
});
}
// Add a new child to an existing family
function add_child_to_family(xref, gender) {
return edit_interface({
"action": "add_child_to_family",
"gender": gender,
"xref": xref
});
}
// Add a new child to an existing individual (creating a one-parent family)
function add_child_to_individual(xref, gender) {
return edit_interface({
"action": "add_child_to_individual",
"gender": gender,
"xref": xref
});
}
// Add a new parent to an existing individual (creating a one-parent family)
function add_parent_to_individual(xref, gender) {
return edit_interface({
"action": "add_parent_to_individual",
"xref": xref,
"gender": gender
});
}
// Add a new spouse to an existing family
function add_spouse_to_family(xref, famtag) {
return edit_interface({
"action": "add_spouse_to_family",
"xref": xref,
"famtag": famtag
});
}
function add_unlinked_indi() {
return edit_interface({
"action": "add_unlinked_indi"
});
}
// Add a new spouse to an existing individual (creating a new family)
function add_spouse_to_individual(xref, famtag) {
return edit_interface({
"action": "add_spouse_to_individual",
"xref": xref,
"famtag": famtag
});
}
function linkspouse(xref, famtag) {
return edit_interface({
"action": "linkspouse",
"xref": xref,
"famtag": famtag,
"famid": "new"
});
}
function add_famc(xref) {
return edit_interface({
"action": "addfamlink",
"xref": xref
});
}
function edit_name(xref, fact_id) {
return edit_interface({
"action": "editname",
"xref": xref,
"fact_id": fact_id
});
}
function add_name(xref) {
return edit_interface({
"action": "addname",
"xref": xref
});
}
// Accept the changes to a record - and reload the page
function accept_changes(xref) {
jQuery.post('action.php', {
action: 'accept-changes',
xref: xref,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
return false;
}
// Reject the changes to a record - and reload the page
function reject_changes(xref) {
jQuery.post('action.php', {
action: 'reject-changes',
xref: xref,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
return false;
}
// Delete a family - and reload the page
function delete_family(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-family',
xref: xref,
ged: typeof gedcom === 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete an individual - and reload the page
function delete_individual(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-individual',
xref: xref,
ged: typeof gedcom === 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a media object - and reload the page
function delete_media(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-media',
xref: xref,
ged: typeof gedcom === 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a note object - and reload the page
function delete_note(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-note',
xref: xref,
ged: typeof gedcom === 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a repository - and reload the page
function delete_repository(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-repository',
xref: xref,
ged: typeof gedcom === 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a source - and reload the page
function delete_source(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-source',
xref: xref,
ged: typeof gedcom === 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a fact - and reload the page
function delete_fact(message, xref, fact_id) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-fact',
xref: xref,
fact_id: fact_id,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Remove links from one record to another - and reload the page
function unlink_media(message, source, target) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'unlink-media',
source: source,
target: target,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Copy a fact to the clipboard
function copy_fact(xref, fact_id) {
jQuery.post('action.php', {
action: 'copy-fact',
xref: xref,
fact_id: fact_id,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
return false;
}
// Paste a fact from the clipboard
function paste_fact(xref, element) {
jQuery.post('action.php', {
action: 'paste-fact',
xref: xref,
fact_id: jQuery(element).val(), // element is the