Commit ff6eec68 authored by Peter Lundin's avatar Peter Lundin
Browse files

Some functions work

parent a8f01407
......@@ -65,7 +65,7 @@
</div>
<form class='cmdbguiSearchForm'>Sök:<input type="text" name="searchString" id="searchString"/></form>
<p class='cmdbguiSmallText'>Innehåll</p>
<div id="displayarea"></div>
<div id="cmdb-table"></div>
<p class='cmdbguiSmallText'>Relationer</p>
<div id="mynetwork"></div>
</body>
......
var inputFormWidth = '500px';
var inputFormFieldWidth = '480px';
var NOT_VISIBLE = 'Ej synlig';
var VISIBLE = 'Synlig';
$(document).ready(function () {
$('#people').jtable({
title: 'Personuppgifter',
paging: true, //Enable paging
pageList: 'minimal',
sorting: true, //Enable sorting
multiSorting: true,
defaultSorting: 'LongHomeName ASC, DateOfBirth ASC', //Set default sorting
rowInserted: function(event, data){
if (false){
data.row.find('.jtable-edit-command-button').hide();
}
},
messages: {addNewRecord: 'Ny person'},
actions: {
listAction: '../entities/listPeople.php',
createAction: '../entities/createPerson.php',
updateAction: function(postData) {
return $.Deferred(function ($dfd) {
$.ajax({
url: '/' + WP_URI + SARON_URI + 'saron/entities/updatePerson.php',
type: 'POST',
dataType: 'json',
data: postData,
success: function (data) {
$dfd.resolve(data);
var records = data['Records'];
//Update Person
_updateHome(records);
_updatePhone(records);
_updateName(records);
_updateMemberState(records);
_updateResidents(records);
_updateCalendarVisability(records);
},
error: function () {
alert('Error in updateAction\r\n' + $dfd.toString());
window.location.href = 'http://localhost/' + WP_URI + SARON_URI + 'saron/';
$dfd.reject();
}
});
});
}
//deleteAction: 'saron/entities/deletePerson.php'
},
fields: {
Homes: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function (homeData) {
//Create an image that will be used to open child table
var $imgHome;
if(homeData.record.HomeId>0){
$imgHome = $('<img src="/' + WP_URI + SARON_URI + 'saron/images/home.png" title="Adressuppgifter" />');
}
else{
$imgHome = $('<img src="/' + WP_URI + SARON_URI + 'saron/images/emptyHome.png" />');
$('#people').jtable({}, $imgHome.closest('tr'),{});
return $imgHome;
}
//Open child table when user clicks the image
$imgHome.click(function () {
$('#people').jtable('openChildTable', $imgHome.closest('tr'),{
title: '<p class="' + _getHomeClassName(homeData.record.HomeId) + '">Hem: ' + homeData.record.LongHomeName + '</p>',
showCloseButton: false,
actions: {
listAction: '../entities/listPeopleHome.php?HomeId=' + homeData.record.HomeId,
updateAction: function(postData) {
return $.Deferred(function ($dfd) {
$.ajax({
url: '/' + WP_URI + SARON_URI + 'saron/entities/updatePeopleHome.php?HomeId=' + homeData.record.HomeId,
type: 'POST',
dataType: 'json',
data: postData,
success: function (data) {
$dfd.resolve(data);
var records = data['Records'];
_updateHome(records);
_updatePhone(records);
},
error: function () {
$dfd.reject();
}
});
});
}
// createAction: 'saron/entities/createPeopleHome.php?HomeId=' + homeData.record.Id
// deleteAction:
},
fields: {
CloseChild: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function () {
var $imgClose = $('<img src="/' + WP_URI + SARON_URI + 'saron/images/cross.png" title="Stäng" />');
$imgClose.click(function () {
$('#people').jtable('closeChildTable', $($imgHome.closest('tr')));
});
return $imgClose;
}
},
Residents:{
edit: false,
title: 'Boende på adressen',
width: '15%',
display: function(data){
return '<p class="' + _getResidentsClassName(data.record.HomeId) + '">' + data.record.Residents + '</>';
}
},
FamilyName: {
list: false,
title: 'Familjenamn'
},
Phone: {
title: 'Tel.',
inputTitle: 'Hemtelefon',
width: '9%',
display: function (data) {
if(data.record.Phone!==null)
return '<p class="numericString">' + data.record.Phone + '</p>';
else
return '<p class="numericString"></p>';
}
},
Co: {
title: 'Co',
width: '15%'
},
Address: {
title: 'Gatuadress',
width: '20%'
},
Zip: {
title: 'PA',
width: '5%',
display: function (homeData){
if(homeData.record.Zip!==null)
return '<p class="numericString">' + homeData.record.Zip + '</p>';
else
return '<p class="numericString"></p>';
}
},
City: {
title: 'Stad',
width: '15%'
},
Country: {
title: 'Land',
width: '15%'
},
Letter: {
inputTitle: 'Församlingspost via brev',
title: 'Brev',
width: '4%',
options:{ 0 : '', 1 : 'Ja'}
}
},
formCreated: function (event, data){
data.row[0].style.backgroundColor = "yellow";
data.form.css('width',inputFormWidth);
data.form.find('input[name=FamilyName]').css('width',inputFormFieldWidth);
data.form.find('input[name=Phone]').css('width',inputFormFieldWidth);
data.form.find('input[name=Co]').css('width',inputFormFieldWidth);
data.form.find('input[name=Address]').css('width',inputFormFieldWidth);
data.form.find('input[name=City]').css('width',inputFormFieldWidth);
data.form.find('input[name=Country]').css('width',inputFormFieldWidth);
data.form.find('input[name=Address]').css('width',inputFormFieldWidth);
var dbox = document.getElementsByClassName('ui-dialog-title');
for (i=0; i<dbox.length; i++)
dbox[i].innerHTML='Uppdatera uppgifter för: ' + data.record.FamilyName;
},
formClosed: function (event, data){
data.row[0].style.backgroundColor = '';
}
},
function (data) { //opened handler
data.childTable.jtable('load');
});
});
//Return image to show on the person row
return $imgHome;
}
},
//Membership
membership: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function (memberData) {
var $imgMember = $('<img src="/' + WP_URI + SARON_URI + 'saron/images/member.png" title="Medlemsuppgifter" />');
$imgMember.click(function () {
$('#people').jtable('openChildTable', $imgMember.closest('tr'),{
title: '<p class="keyValue">Medlemsuppgifter för: ' + memberData.record.Name + '</p>',
showCloseButton: false,
actions: {
listAction: '../entities/listPeopleMembership.php?PersonId=' + memberData.record.PersonId,
updateAction: function(postData) {
return $.Deferred(function ($dfd) {
$.ajax({
url: '/' + WP_URI + SARON_URI + 'saron/entities/updatePersonMembership.php?PersonId=' + memberData.record.PersonId,
type: 'POST',
dataType: 'json',
data: postData,
success: function (data) {
$dfd.resolve(data);
var records = data['Records'];
_updateMemberState(records);
},
error: function () {
$dfd.reject();
}
});
});
}
//createAction: 'saron/entities/createPeopleHome.php?HomeId=' + homeData.record.Id
//deleteAction:
},
fields: {
CloseChild: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function() {
var $imgClose = $('<img src="/' + WP_URI + SARON_URI + 'saron/images/cross.png" title="Stäng" />');
$imgClose.click(function() {
$('#people').jtable('closeChildTable', $imgMember.closest('tr'));
return;
});
return $imgClose;
}
},
Id: {
key: true,
update: false,
create: false,
type: 'hidden',
defaultValue: memberData.record.PersonId
},
PreviousCongregation: {
title: 'Kommit från församling',
width: '20%'
},
DateOfMembershipStart: {
width: '7%',
display: function (memberData) {
return _parseDate(memberData.record.DateOfMembershipStart, false);
},
type: 'date',
title: 'Start'
},
MembershipNo: {
width: '3%',
display: function (memberData) {
if(memberData.record.MembershipNo>0)
return '<p class="numericString">' + memberData.record.MembershipNo + '</p>';
else
return '<p class="numericString"></p>';
},
title: 'Nr.',
options: '/' + WP_URI + SARON_URI + 'saron/entities/listNextMembershipNo.php?PersonId=' + memberData.record.PersonId
},
DateOfMembershipEnd: {
display: function (memberData) {
return _parseDate (memberData.record.DateOfMembershipEnd, false);
},
width: '7%',
type: 'date',
title: 'Avslut'
},
NextCongregation: {
width: '20%',
title: 'Flyttat till församling'
},
Comment: {
type: 'textarea',
width: '40%',
title: 'Not'
}
},
formCreated: function (event, data){
data.row[0].style.backgroundColor = "yellow";
data.form.css('width',inputFormWidth);
data.form.find('input[name=PreviousCongregation]').css('width',inputFormFieldWidth);
data.form.find('input[name=NextCongregation]').css('width',inputFormFieldWidth);
data.form.find('input[name=Comment]').css('width',inputFormFieldWidth);
var dbox = document.getElementsByClassName('ui-dialog-title');
for (i=0; i<dbox.length; i++)
dbox[i].innerHTML='Uppdatera uppgifter för: ' + data.record.FirstName + ' ' + data.record.LastName;
},
formClosed: function (event, data){
data.row[0].style.backgroundColor = '';
}
},
function (data) { //opened handler
data.childTable.jtable('load');
});
});
//Return Membership image to show on the person row
return $imgMember;
}
},
//Baptism
baptism: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function (baptistData) {
//Create an image that will be used to open child table
var $imgBaptist = $('<img src="/' + WP_URI + SARON_URI + 'saron/images/baptist.png" title="Dopuppgifter" />');
//Open child table when user clicks the image
$imgBaptist.click(function () {
$('#people').jtable('openChildTable', $imgBaptist.closest('tr'),{
title: '<p class="keyValue">Dopuppgifter för: ' + baptistData.record.Name + '</p>',
showCloseButton: false,
actions: {
listAction: '../entities/listPeopleBaptist.php?PersonId=' + baptistData.record.PersonId,
updateAction: function(postData) {
return $.Deferred(function ($dfd) {
$.ajax({
url: '/' + WP_URI + SARON_URI + 'saron/entities/updatePersonBaptist.php?PersonId=' + baptistData.record.PersonId,
type: 'POST',
dataType: 'json',
data: postData,
success: function (data) {
$dfd.resolve(data);
var records = data['Records'];
_updateBaptistCongregation(records);
},
error: function () {
$dfd.reject();
}
});
});
}
//createAction: 'saron/entities/createPeopleHome.php?HomeId=' + homeData.record.Id
//deleteAction:
},
fields: {
CloseChild: {
title: '',
width: '1%',
sorting: false,
edit: false,
create: false,
delete: false,
display: function (memberData) {
var $imgClose = $('<img src="/' + WP_URI + SARON_URI + 'saron/images/cross.png" title="Stäng" />');
$imgClose.click(function () {
$('#people').jtable('closeChildTable', $($imgBaptist.closest('tr')));
});
return $imgClose;
}
},
Id: {
key: true,
update: false,
create: false,
type: 'hidden',
defaultValue: baptistData.record.PersonId
},
CongregationOfBaptismThis: {
list: false,
with: '20%',
title: 'Döpt',
options: '/' + WP_URI + SARON_URI + 'saron/entities/listBaptismOption.php'
},
CongregationOfBaptism: {
edit: true,
create: false,
width: '20%',
title: 'Dopförsamling',
display: function(data){
if(data.record.CongregationOfBaptism!==null)
return '<p class="' + _getBaptistConcregationClassName(data.record.PersonId) + '">' + data.record.CongregationOfBaptism + '</p>';
else
return '<p class="' + _getBaptistConcregationClassName(data.record.PersonId) + '"></p>';
}
},
DateOfBaptism: {
width: '7%',
type: 'date',
display: function (baptistData) {
return _parseDate(baptistData.record.DateOfBaptism, false);
},
title: 'Dopdatum'
},
Baptister: {
width: '20%',
title: 'Dopförrättare'
},
Comment: {
type: 'textarea',
width: '35%',
title: 'Not'
}
}, //Baptist
formCreated: function (event, data){
data.row[0].style.backgroundColor = "yellow";
data.form.css('width',inputFormWidth);
data.form.find('input[name=Baptister]').css('width',inputFormFieldWidth);
data.form.find('input[name=CongregationOfBaptism]').css('width',inputFormFieldWidth);
data.form.find('input[name=Comment]').css('width',inputFormFieldWidth);
var dbox = document.getElementsByClassName('ui-dialog-title');
for (i=0; i<dbox.length; i++)
dbox[i].innerHTML='Uppdatera uppgifter för: ' + data.record.FirstName + ' ' + data.record.LastName;
//...
},
formClosed: function (event, data){
data.row[0].style.backgroundColor = '';
}
},
function (data) { //opened handler
data.childTable.jtable('load');
});
});
//Return image to show on the person row
return $imgBaptist;
}
},
HomeId: {
create: true,
edit: true,
list: true,
title: 'Hem',
inputTitle: 'Välj hem',
display: function(data){
if(data.record.LongHomeName!==null)
return '<p class="' + _getHomeClassName(data.record.HomeId) + '">' + data.record.LongHomeName + '</p>';
else
return '<p class="' + _getHomeClassName(data.record.HomeId) + '"> Inget hem</p>';
},
options: function(data){
if(data.source !== 'list')
data.clearCache();
return '/' + WP_URI + SARON_URI + 'saron/entities/listHomes.php';
}
},
PersonId: {
key: true,
list: false,
create: false,
edit: false,
update: false
},
LastName: {
title: 'Efternamn',
list: false,
display: function (data) {
return '<p class="keyValue">' + data.record.LastName + '</p>';
}
},
FirstName: {
title: 'Förnamn',
list: false,
display: function (data) {
return '<p class="keyValue">' + data.record.FirstName + '</p>';
}
},
Name: {
title: 'Namn',
width: '10%',
list: true,
create: false,
edit: false,
display: function (data) {
return '<p class="keyValue '+ _getNameClassName(data.record.PersonId) +'">' + data.record.Name + '</p>';
}
},
DateOfBirth: {
title: 'Född',
width: '5%',
type: 'date',
display: function (data) {
return _parseDate (data.record.DateOfBirth, true);
}
},
Gender: {
title: 'Kön',
width: '2%',
options:{ 0 : '-', 1 : 'Man', 2 : 'Kvinna'}
},
Email: {
title: 'Mail',
display: function (data) {
return _getMailLink(data.record.Email, data.record.PersonId);
},
width: '13%'
},
Mobile: {
title: 'Mobil',
inputTitle: 'Mobil <BR> - Hemtelefonuppgifter matas in under "Adressuppgifter"',
width: '7%',
display: function (data) {
if(data.record.Mobile!==null)
return '<p class="numericString">' + data.record.Mobile + '</p>';
else
return '<p class="numericString"></p>';
}
},
Phone: {
title: 'Tel.',
edit: false,
width: '7%',
create: false,
display: function (data) {
if(data.record.Phone!==null)
return '<p class="numericString ' + _getPhoneClassName(data.record.HomeId) + '">' + data.record.Phone + '</p>';
else
return '<p class="numericString ' + _getPhoneClassName(data.record.HomeId) + '"></p>';
}
},
DateOfMembershipStart: {
edit: false,
title: 'Medlemskap start',
list: false,
width: '5%',
type: 'date',
display: function (data) {
return _parseDate(data.record.DateOfMembershipStart,false);
}
},
MembershipNo: {
list: false,
edit: false,
title: 'Medlemsnummer',
display: function (data) {
if(data.record.MembershipNo>0)
return '<p class="numericString">' + data.record.MembershipNo + '</p>';
else
return '<p class="numericString"></p>';
},
options: '/' + WP_URI + SARON_URI + 'saron/entities/listNextMembershipNo.php?PersonId=null'
},
MemberState: {
title: 'Status',
edit: false,
create: false,
width: '4%',
display: function (memberData){
return '<p class="' + _getMemberStateClassName(memberData.record.PersonId) + '">' + memberData.record.MemberState + '</p>';
}
},
VisibleInCalendar: {
edit: 'true',