Author: david
Date: 2008-11-10 17:50:45 -0800 (Mon, 10 Nov 2008)
New Revision: 1556
Added:
trunk/qubit/apps/qubit/modules/event/actions/showAction.class.php
Modified:
trunk/qubit/apps/qubit/modules/informationobject/templates/_newActorEventDialog.php
trunk/qubit/web/js/newActorEventDialog.js
Log:
Start work on javascript to allow editing actorEvents via YUI dialog. Add
event/showAction.class.php to return JSON formatted data about actor events.
Added: trunk/qubit/apps/qubit/modules/event/actions/showAction.class.php
===================================================================
--- trunk/qubit/apps/qubit/modules/event/actions/showAction.class.php
(rev 0)
+++ trunk/qubit/apps/qubit/modules/event/actions/showAction.class.php
2008-11-11 01:50:45 UTC (rev 1556)
@@ -0,0 +1,79 @@
+<?php
+/*
+ * This file is part of the Qubit Toolkit.
+ * Copyright (C) 2006-2008 Peter Van Garderen <[EMAIL PROTECTED]>
+ *
+ * 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 2 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 Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+class EventShowAction extends sfAction
+{
+ public function execute($request)
+ {
+ if (true || $request->isXmlHttpRequest())
+ {
+ $criteria = new Criteria;
+ $criteria->add(QubitEvent::ID, $request->getParameter('id'),
Criteria::EQUAL);
+
+ $actorEvent = QubitEvent::getOne($criteria);
+
+ if (null !== $actorEvent)
+ {
+ $properties['id'] = $actorEvent->getId();
+ $properties['actorId'] = $actorEvent->getActorId();
+ $properties['eventTypeId'] = $actorEvent->getTypeId();
+ //$properties['placeId'] = $actorEvent->getPlaceId();
+
+ if ($actorEvent->getStartDate() != '0000-00-00')
+ {
+ $properties['year'] = date('Y',
strtotime($actorEvent->getStartDate()));
+ }
+ else
+ {
+ $properties['year'] = '';
+ }
+
+ if ($actorEvent->getEndDate() != '0000-00-00')
+ {
+ $properties['endYear'] = date('Y',
strtotime($actorEvent->getEndDate()));
+ }
+ else
+ {
+ $properties['endYear'] = '';
+ }
+
+ $properties['dateDisplay'] = $actorEvent->getDateDisplay();
+ $properties['description'] = $actorEvent->getDescription();
+
+ // Build JSON string
+ $jsonStr = '( {';
+ foreach ($properties as $key => $val)
+ {
+ $jsonStr .= ' "'.$key.'": "'.$val.'", ';
+ }
+ $jsonStr = substr($jsonStr, 0, -2); // Chop trailing ", "
+ $jsonStr .= ' } )';
+
+ return $this->renderText($jsonStr);
+ }
+ else
+ {
+ return $this->renderText('{}');
+ }
+ }
+
+ return $this->renderText('');
+ }
+}
\ No newline at end of file
Property changes on:
trunk/qubit/apps/qubit/modules/event/actions/showAction.class.php
___________________________________________________________________
Added: svn:keywords
+ Author Id Revision
Added: svn:eol-style
+ native
Modified:
trunk/qubit/apps/qubit/modules/informationobject/templates/_newActorEventDialog.php
===================================================================
---
trunk/qubit/apps/qubit/modules/informationobject/templates/_newActorEventDialog.php
2008-11-11 01:46:48 UTC (rev 1555)
+++
trunk/qubit/apps/qubit/modules/informationobject/templates/_newActorEventDialog.php
2008-11-11 01:50:45 UTC (rev 1556)
@@ -18,9 +18,10 @@
* Dialog object, so we don't see them when Javascript is turned off. Include
* them here (instead of in .js file) to allow PHP to parse i18n tags.
*/
-
- // Get i18n labels
+
+ // Make Qubit variables available to javascript
Qubit.labels = ({"unknown": "<?php echo __('unknown') ?>"});
+ Qubit.paths = ({"eventShow": "<?php echo url_for('event/show') ?>"});
// Do this after newActorEventDialog.js actions
Drupal.behaviors.writeNewActorEventHTML = function(context)
@@ -39,7 +40,7 @@
);
// build the dialog
- renderEventDialog();
+ renderActorEventDialog();
// Write a link to show the dialog
$("table#actorEvents").append('<tr id="addActorEventLink"><td colspan="4"
style="text-align: right"><a
href="javascript:Qubit.newActorEventDialog.show()"><?php echo __('add new')
?></a></td></tr>');
Modified: trunk/qubit/web/js/newActorEventDialog.js
===================================================================
--- trunk/qubit/web/js/newActorEventDialog.js 2008-11-11 01:46:48 UTC (rev
1555)
+++ trunk/qubit/web/js/newActorEventDialog.js 2008-11-11 01:50:45 UTC (rev
1556)
@@ -6,94 +6,168 @@
$('input.addedHidden'+index).remove();
}
-function renderEventDialog(context)
+function editActorEventDialog(eventId)
{
- var i = 0; // Counter
+ // Check for a local data cache for this event
+ var actorEventData = $('body').data('actorEvent'+eventId);
- // Write data from dialog to informationobject/edit form for submission.
- var handleSubmit = function() {
- var thisData = this.getData();
- var actorSelector = $('table#newActorEvent
select[name="newActorEvent[actorId]"]');
- var eventTypeSelector = $('table#newActorEvent
select[name="newActorEvent[eventTypeId]"]');
- var placeSelector = $('table#newActorEvent
select[name="newActorEvent[placeId]"]');
+ if (actorEventData != undefined)
+ {
+ // Populate actorEvent dialog with cached data, then show it
+ populateActorEventDialog(actorEventData);
+ Qubit.newActorEventDialog.show();
+ }
+ else
+ {
+ // If no local data cache found, do ajax call
+ getActorEventAjax(eventId);
+ }
+}
- // Hide dialog
- this.hide();
+function getActorEventAjax(eventId)
+{
+ $.getJSON( Qubit.paths.eventShow+'?id='+eventId+'&returnFormat=json',
+ function(data) {
+ // cache data locally so we don't have to hit the database again
+ $('body').data('actorEvent'+eventId, data);
- // Build hidden form input fields
- var newHiddens = '';
- newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][actorId]"
value="'+thisData['newActorEvent[actorId]']+'" />\n';
- newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][newActorAuthorizedName]"
value="'+thisData['newActorEvent[newActorAuthorizedName]']+'" />\n';
- newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][eventTypeId]"
value="'+thisData['newActorEvent[eventTypeId]']+'" />\n';
- newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][placeId]"
value="'+thisData['newActorEvent[placeId]']+'" />\n';
- newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][year]" value="'+thisData['newActorEvent[year]']+'"
/>\n';
- newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][endYear]"
value="'+thisData['newActorEvent[endYear]']+'" />\n';
- newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][dateDisplay]"
value="'+thisData['newActorEvent[dateDisplay]']+'" />\n';
- newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][description]"
value="'+thisData['newActorEvent[description]']+'" />\n';
+ // Populate and show the dialog form
+ populateActorEventDialog(data);
+ Qubit.newActorEventDialog.show();
+ } );
+}
- // Append hidden input fields
- $('table#actorEvents').append(newHiddens);
+function populateActorEventDialog(data)
+{
+ var dialog = $('table#newActorEvent');
- // Determine the actor name to show in the creation events table
- var actorId = thisData['newActorEvent[actorId]'];
- var nameDisplay = Qubit.labels.unknown;
- if (actorId > 0)
- {
- nameDisplay = actorSelector.find('option:selected').text();
- }
- else if (thisData['newActorEvent[newActorAuthorizedName]'].length > 0)
- {
- nameDisplay = thisData['newActorEvent[newActorAuthorizedName]'];
- }
+ // Set fields
+ dialog.find('input[name="newActorEvent[year]"]').val(data.year);
+ dialog.find('input[name="newActorEvent[endYear]"]').val(data.endYear);
+
dialog.find('input[name="newActorEvent[dateDisplay]"]').val(data.dateDisplay);
+
dialog.find('input[name="newActorEvent[description]"]').val(data.description);
- // Determine the date(s) to show in the creation events table
- var dateDisplay = thisData['newActorEvent[dateDisplay]'];
- if (dateDisplay.length == 0 && thisData['newActorEvent[year]'].length > 0)
- {
- dateDisplay = thisData['newActorEvent[year]'];
- if (thisData['newActorEvent[endYear]'].length > 0)
- {
- dateDisplay += ' - '+thisData['newActorEvent[endYear]'];
- }
- }
+ // Select correct actor in selectbox
+ var actorIdOption = dialog.find('select[name="newActorEvent[actorId]"]
option[value='+data.actorId+']');
+ if (actorIdOption.length > 0)
+ {
+ actorIdOption.get(0).selected = true;
+ }
- // Get event type text
- var eventTypeId = thisData['newActorEvent[eventTypeId]'];
- var eventTypeDisplay = '';
- if (eventTypeId.length > 0)
+ // Select correct place in selectbox
+ var eventTypeIdOption =
dialog.find('select[name="newActorEvent[eventTypeId]"]
option[value='+data.eventTypeId+']');
+ if (eventTypeIdOption.length > 0)
+ {
+ eventTypeIdOption.get(0).selected = true;
+ }
+
+ // Select correct place in selectbox
+ var placeIdOption = dialog.find('select[name="newActorEvent[placeId]"]
option[value='+data.placeId+']');
+ if (placeIdOption.length > 0)
+ {
+ placeIdOption.get(0).selected = true;
+ }
+}
+
+function clearActorEventDialog()
+{
+ var actorSelector = $('table#newActorEvent
select[name="newActorEvent[actorId]"]');
+ var eventTypeSelector = $('table#newActorEvent
select[name="newActorEvent[eventTypeId]"]');
+ var placeSelector = $('table#newActorEvent
select[name="newActorEvent[placeId]"]');
+
+ // Clear data out of yui dialog
+ $('table#newActorEvent
input[name="newActorEvent[newActorAuthorizedName]"]').val('');
+ $('table#newActorEvent input[name="newActorEvent[year]"]').val('');
+ $('table#newActorEvent input[name="newActorEvent[endYear]"]').val('');
+ $('table#newActorEvent input[name="newActorEvent[dateDisplay]"]').val('');
+ $('table#newActorEvent input[name="newActorEvent[description]"]').val('');
+ actorSelector.get(0).options[0].selected = true;
+ eventTypeSelector.get(0).options[0].selected = true;
+ placeSelector.get(0).options[0].selected = true;
+
+ return true;
+}
+
+function submitNewActorEventDialog(thisData, i)
+{
+ var actorSelector = $('table#newActorEvent
select[name="newActorEvent[actorId]"]');
+ var eventTypeSelector = $('table#newActorEvent
select[name="newActorEvent[eventTypeId]"]');
+ var placeSelector = $('table#newActorEvent
select[name="newActorEvent[placeId]"]');
+
+ // Build hidden form input fields
+ var newHiddens = '';
+ newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][actorId]"
value="'+thisData['newActorEvent[actorId]']+'" />\n';
+ newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][newActorAuthorizedName]"
value="'+thisData['newActorEvent[newActorAuthorizedName]']+'" />\n';
+ newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][eventTypeId]"
value="'+thisData['newActorEvent[eventTypeId]']+'" />\n';
+ newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][placeId]"
value="'+thisData['newActorEvent[placeId]']+'" />\n';
+ newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][year]" value="'+thisData['newActorEvent[year]']+'"
/>\n';
+ newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][endYear]"
value="'+thisData['newActorEvent[endYear]']+'" />\n';
+ newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][dateDisplay]"
value="'+thisData['newActorEvent[dateDisplay]']+'" />\n';
+ newHiddens += '<input class="addedHidden'+i+'" type="hidden"
name="newActorEvents['+i+'][description]"
value="'+thisData['newActorEvent[description]']+'" />\n';
+
+ // Append hidden input fields
+ $('table#actorEvents').append(newHiddens);
+
+ // Determine the actor name to show in the creation events table
+ var actorId = thisData['newActorEvent[actorId]'];
+ var nameDisplay = '';
+ if (actorId > 0)
+ {
+ nameDisplay = actorSelector.find('option:selected').text();
+ }
+ else if (thisData['newActorEvent[newActorAuthorizedName]'].length > 0)
+ {
+ nameDisplay = thisData['newActorEvent[newActorAuthorizedName]'];
+ }
+
+ // Determine the date(s) to show in the creation events table
+ var dateDisplay = thisData['newActorEvent[dateDisplay]'];
+ if (dateDisplay.length == 0 && thisData['newActorEvent[year]'].length > 0)
+ {
+ dateDisplay = thisData['newActorEvent[year]'];
+ if (thisData['newActorEvent[endYear]'].length > 0)
{
- eventTypeDisplay = eventTypeSelector.find('option:selected').text()
+ dateDisplay += ' - '+thisData['newActorEvent[endYear]'];
}
+ }
- // Build visible row to append to the creationEvents Table
- var newRow = $('<tr id="newRow'+i+'">'+
- '<td><div>'+nameDisplay+'</div></td>'+
- '<td><div>'+eventTypeDisplay+'<div></td>'+
- '<td><div>'+dateDisplay+'<div></td>'+
- '<td><div><a href="javascript:removeRow('+i+')"><img
src="'+$('img#imagesDeletePng').attr('src')+'" /></a></div></td>'+
- '</tr>'
- );
+ // Get event type text
+ var eventTypeId = thisData['newActorEvent[eventTypeId]'];
+ var eventTypeDisplay = '';
+ if (eventTypeId.length > 0)
+ {
+ eventTypeDisplay = eventTypeSelector.find('option:selected').text()
+ }
- // Append visible row showing actor name and event note
- $('div', newRow).hide();
- newRow.insertBefore('table#actorEvents tr#addActorEventLink');
- $('div', newRow).show('normal');
+ // Build visible row to append to the creationEvents Table
+ var newRow = $('<tr id="newRow'+i+'">'+
+ '<td><div>'+nameDisplay+'</div></td>'+
+ '<td><div>'+eventTypeDisplay+'<div></td>'+
+ '<td><div>'+dateDisplay+'<div></td>'+
+ '<td style="text-align: right"><div><a
href="javascript:removeRow('+i+')"><img
src="'+$('img#imagesDeletePng').attr('src')+'" align="top" /></a></div></td>'+
+ '</tr>'
+ );
- // Clear data out of yui dialog
- $('table#newActorEvent
input[name="newActorEvent[newActorAuthorizedName]"]').val('');
- $('table#newActorEvent input[name="newActorEvent[year]"]').val('');
- $('table#newActorEvent input[name="newActorEvent[endYear]"]').val('');
- $('table#newActorEvent input[name="newActorEvent[dateDisplay]"]').val('');
- $('table#newActorEvent input[name="newActorEvent[description]"]').val('');
- actorSelector.get(0).options[0].selected = true;
- eventTypeSelector.get(0).options[0].selected = true;
- placeSelector.get(0).options[0].selected = true;
+ // Append visible row showing actor name and event note
+ $('div', newRow).hide();
+ newRow.insertBefore('table#actorEvents tr#addActorEventLink');
+ $('div', newRow).show('normal');
+}
- i++; // increment counter
+function renderActorEventDialog(context)
+{
+ var i = 0; // Counter
+
+ // Write data from dialog to informationobject/edit form for submission.
+ var handleSubmit = function() {
+ submitNewActorEventDialog(this.getData(), i++); // Save the data to the
main form
+ this.hide(); // Hide dialog
+ clearActorEventDialog(); // Clear the dialog form
};
var handleCancel = function() {
this.cancel();
+ clearActorEventDialog();
};
// Move newActorEvent table contents into yui dialog container.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---