Author: david
Date: 2008-11-05 16:19:11 -0800 (Wed, 05 Nov 2008)
New Revision: 1525

Added:
   
trunk/qubit/apps/qubit/modules/informationobject/templates/_addAccessPointTermDialog.php
   trunk/qubit/web/js/addAccessPointTermDialog.js
Modified:
   
trunk/qubit/apps/qubit/modules/informationobject/templates/editIsadSuccess.php
   trunk/qubit/apps/qubit/modules/term/actions/updateAction.class.php
   trunk/qubit/web/js/multiInstanceSelect.js
Log:
Add javascript to add subject and place terms from the "Access Points" section 
of the informationobject/edit form.

Added: 
trunk/qubit/apps/qubit/modules/informationobject/templates/_addAccessPointTermDialog.php
===================================================================
--- 
trunk/qubit/apps/qubit/modules/informationobject/templates/_addAccessPointTermDialog.php
                            (rev 0)
+++ 
trunk/qubit/apps/qubit/modules/informationobject/templates/_addAccessPointTermDialog.php
    2008-11-06 00:19:11 UTC (rev 1525)
@@ -0,0 +1,79 @@
+<?php use_helper('Javascript') ?>
+<?php 
$sf_response->addJavaScript('/vendor/yui/yahoo-dom-event/yahoo-dom-event') ?>
+<?php $sf_response->addJavaScript('/vendor/yui/animation/animation-min') ?>
+<?php $sf_response->addJavaScript('/vendor/yui/dragdrop/dragdrop-min') ?>
+<?php $sf_response->addJavaScript('/vendor/yui/connection/connection-min') ?>
+<?php $sf_response->addJavaScript('/vendor/yui/container/container-min') ?>
+<?php $sf_response->addJavaScript('/js/qubit') ?>
+<?php $sf_response->addJavaScript('/js/addAccessPointTermDialog') ?>
+<?php 
$sf_response->addStylesheet('/vendor/yui/container/assets/skins/sam/container') 
?>
+
+<script language="javascript">
+//<!CDATA[
+  /*
+   * Dynamically write form elements specific to the newCreationEventDialog YUI
+   * 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. 
+   */
+  
+  function appendNewOption(thisSelector, thisId, thisName) 
+  {
+    var newOption = '<option value="'+thisId+'">'+thisName+'</option>';
+    
+    thisSelector.append(newOption); // append option
+    thisSelector.find('option:last').get(0).selected = true; // select it
+  }
+  
+  function showSubjectAccessPointDialog()
+  {
+    $('#addAccessPointTermDialog input[name=taxonomy_id]').val('<?php echo 
QubitTaxonomy::SUBJECT_ID ?>');
+    $('#addAccessPointTermDialog').data('target', 'subjectAccessPoints');
+    Qubit.addAccessPointTermDialog.show()
+  }
+  
+  function showPlaceAccessPointDialog()
+  {
+    $('#addAccessPointTermDialog input[name=taxonomy_id]').val('<?php echo 
QubitTaxonomy::PLACE_ID ?>');
+    $('#addAccessPointTermDialog').data('target', 'placeAccessPoints');
+    Qubit.addAccessPointTermDialog.show()
+  }
+  
+  Drupal.behaviors.writeAddAccessPointHTML = function(context) 
+  {
+    // Create a happy, hidden YUI dialog
+    $('body').prepend(' \
+      <div class="yui-skin-sam"> \
+        <div id="addAccessPointTermDialog"> \
+          <div class="hd"><?php echo __('enter term and scope') ?></div> \
+          <div class="bd" style="text-align: left"> \
+            <form action="<?php echo url_for('term/update') ?>" method="POST"> 
\
+              <input type="hidden" name="responseFormat" value="json" /> \
+              <input type="hidden" name="taxonomy_id" value="<?php echo 
QubitTaxonomy::SUBJECT_ID ?>" /> \
+              <div class="form-item"> \
+                <label for="addSubjectTermName"><?php echo __('term name') 
?></label> \
+                <input id="addSubjectTermName" type="text" name="name" 
value="" /> \
+              </div> \
+              <div class="form-item"> \
+                <label for="addSubjectTermScope"><?php echo __('scope note') 
?></label> \
+                <input id="addSubjectTermScope" type="text" 
name="new_scope_note" value="" /> \
+              </div> \
+            </form> \
+          </div> \
+        </div> \
+      </div> \
+'   );
+  
+    // Move newCreationEvent table contents into yui dialog container.
+    // Why? So the standard form still works if javascript is disabled
+    var nceTable = $('table#newCreationEvent');
+    nceTable.clone().appendTo('#newCreationEventDialog div.bd form');
+    nceTable.remove();
+    
+    renderAccessPointTermDialog();
+  
+    // Write a link to open the form
+    $("#addSubjectAccessPointLink").append(' [ <a 
href="javascript:showSubjectAccessPointDialog()"><?php echo __('add a subject') 
?></a> ] ');
+    $("#addPlaceAccessPointLink").append(' [ <a 
href="javascript:showPlaceAccessPointDialog()"><?php echo __('add a place') 
?></a> ] ');
+  }
+//]]>
+</script>


Property changes on: 
trunk/qubit/apps/qubit/modules/informationobject/templates/_addAccessPointTermDialog.php
___________________________________________________________________
Added: svn:keywords
   + Author Id Revision
Added: svn:eol-style
   + native

Modified: 
trunk/qubit/apps/qubit/modules/informationobject/templates/editIsadSuccess.php
===================================================================
--- 
trunk/qubit/apps/qubit/modules/informationobject/templates/editIsadSuccess.php  
    2008-11-05 23:44:36 UTC (rev 1524)
+++ 
trunk/qubit/apps/qubit/modules/informationobject/templates/editIsadSuccess.php  
    2008-11-06 00:19:11 UTC (rev 1525)
@@ -339,9 +339,10 @@
 
   <fieldset class="collapsible collapsed">
     <legend><?php echo __('access points'); ?></legend>
-
-    <div class="form-item">
-      <label for="subject_id"><?php echo __('subject access points'); 
?></label>
+    
+    <?php include_partial('addAccessPointTermDialog') ?>
+    <div class="form-item" id="subjectAccessPoints">
+      <label for="subject_id"><?php echo __('subject access points'); ?><span 
id="addSubjectAccessPointLink"></span></label>
       <?php if ($subjectAccessPoints): ?>
         <?php foreach ($subjectAccessPoints as $subject): ?>
           <?php echo $subject->getTerm() ?>&nbsp;<?php echo 
link_to(image_tag('delete', 'align=top'), 
'informationobject/deleteTermRelation?TermRelationId='.$subject->getId().'&returnTemplate=editIsad')
 ?><br/>
@@ -350,8 +351,8 @@
       <?php echo object_select_tag($newSubjectAccessPoint, 'getTermId', 
array('name' => 'subject_id', 'id' => 'subject_id', 'include_blank' => true, 
'peer_method' => 'getSubjects', 'class'=>'multiInstance')) ?>
     </div>
 
-    <div class="form-item">
-      <label for="place_id"><?php echo __('place access points'); ?></label>
+    <div class="form-item" id="placeAccessPoints">
+      <label for="place_id"><?php echo __('place access points'); ?><span 
id="addPlaceAccessPointLink"></span></label>
       <?php if ($placeAccessPoints): ?>
         <?php foreach ($placeAccessPoints as $place): ?>
           <?php echo $place->getTerm() ?>&nbsp;<?php echo 
link_to(image_tag('delete', 'align=top'), 
'informationobject/deleteTermRelation?TermRelationId='.$place->getId().'&returnTemplate=editIsad')
 ?><br/>

Modified: trunk/qubit/apps/qubit/modules/term/actions/updateAction.class.php
===================================================================
--- trunk/qubit/apps/qubit/modules/term/actions/updateAction.class.php  
2008-11-05 23:44:36 UTC (rev 1524)
+++ trunk/qubit/apps/qubit/modules/term/actions/updateAction.class.php  
2008-11-06 00:19:11 UTC (rev 1525)
@@ -31,19 +31,6 @@
     {
       $term = QubitTerm::getById($this->getRequestParameter('id'));
       $this->forward404Unless($term);
-
-/*
-      //make sure a locked term value is not updated
-      $termRestriction = $term->getTaxonomy()->getTermUse();
-      if ($termRestriction == 'admin')
-        {
-        $this->forward('admin','TermPermission');
-        }
-      else if ($term->getLocked())
-        {
-        $this->forward('admin','TermPermission');
-        }
-*/
     }
 
     $term->setId($this->getRequestParameter('id'));
@@ -62,12 +49,17 @@
       $term->setNote($this->getUser()->getAttribute('user_id'), 
$this->getRequestParameter('new_source_note'), QubitTerm::SOURCE_NOTE_ID);
     }
 
-    if ($this->getRequestParameter('content'))
+    $taxonomyId = $term->getTaxonomyId();
 
+    // If requesting a json response object
+    if ($request->getParameter('responseFormat') == 'json')
+    {
+      $jsonObject = '({"id": "'.$term->getId().'", "name": 
"'.$term->getName().'"})';
 
+      // Return json object
+      return $this->renderText($jsonObject);
+    }
 
-    $taxonomyId = $term->getTaxonomyId();
-
     return 
$this->redirect('term/list?taxonomyId='.$this->getRequestParameter('taxonomy_id'));
   }
 }

Added: trunk/qubit/web/js/addAccessPointTermDialog.js
===================================================================
--- trunk/qubit/web/js/addAccessPointTermDialog.js                              
(rev 0)
+++ trunk/qubit/web/js/addAccessPointTermDialog.js      2008-11-06 00:19:11 UTC 
(rev 1525)
@@ -0,0 +1,62 @@
+// $Id$
+
+function removeRow(index)
+{
+  $('tr#newRow'+index+' div').hide('normal', function() { 
$('tr#newRow'+index).remove() });
+  $('input.addedHidden'+index).remove();
+}
+
+function renderAccessPointTermDialog(context)
+{
+  var i = 0; // Counter
+
+  // Write data from dialog to informationobject/edit form for submission.
+  var handleSubmit = function() {
+    this.submit();
+  };
+
+  var handleCancel = function() {
+    this.cancel();
+  };
+
+  // Instantiate the Dialog
+  Qubit.addAccessPointTermDialog = new 
YAHOO.widget.Dialog("addAccessPointTermDialog",
+  {
+    width : "300px",
+    fixedcenter : true,
+    visible : false,
+    modal : true,
+    constraintoviewport : true,
+    postmethod : 'async',
+    buttons : [ { text:"Submit", handler:handleSubmit, isDefault:true },
+                { text:"Cancel", handler:handleCancel } ],
+    effect : { effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25 }
+  } );
+
+  var onSuccess = function(o) {
+    var data = eval(o.responseText);
+    var target = $('#addAccessPointTermDialog').data('target');
+    var thisSelector = $('div#'+target+' select:last');
+
+    if (thisSelector.length > 0)
+    {
+      // Append this new term to the select list
+      appendNewOption(thisSelector, data.id, data.name);
+
+      // spawn new selector
+      multiInstanceSelector(thisSelector);
+    }
+
+    // Clear the Dialog fields
+    $('div#addAccessPointTermDialog input#addSubjectTermName').val('');
+    $('div#addAccessPointTermDialog input#addSubjectTermScope').val('');
+  }
+
+  var onFailure = function(o) {
+    alert("Your submission failed. Status: " + o.status);
+  }
+
+  Qubit.addAccessPointTermDialog.callback.success = onSuccess;
+  Qubit.addAccessPointTermDialog.callback.failure = onFailure;
+  Qubit.addAccessPointTermDialog.render();
+}
\ No newline at end of file


Property changes on: trunk/qubit/web/js/addAccessPointTermDialog.js
___________________________________________________________________
Added: svn:keywords
   + Author Id Revision
Added: svn:eol-style
   + native

Modified: trunk/qubit/web/js/multiInstanceSelect.js
===================================================================
--- trunk/qubit/web/js/multiInstanceSelect.js   2008-11-05 23:44:36 UTC (rev 
1524)
+++ trunk/qubit/web/js/multiInstanceSelect.js   2008-11-06 00:19:11 UTC (rev 
1525)
@@ -1,5 +1,8 @@
 // Add string method for removing trailing numeric characters
-String.prototype.trimTrailingDigits = function() { return this.replace(/\d+$/, 
''); };
+String.prototype.trimTrailingDigits = function()
+{
+  return this.replace(/\d+$/, '');
+};
 
 /**
  * Javascript to spawn new select box to create multiple relations per form 
submit.
@@ -8,48 +11,44 @@
  * @return void
  */
 function multiInstanceSelector(thisElement)
-{   
-  var static 
+{
+  var static
   var elementName = thisElement.attr('name').toString();
-  
+
   // Append array braces '[]' to element name (if not present)
   if (elementName.substr(-2) != '[]')  {
     thisElement.attr('name', elementName += '[]');
   }
-  
+
   // String to select all elements in this set
   var setSelector = "[name='"+elementName+"']";
-  
+
   // Remove element if blank and it's not the only element in the set
   if (thisElement.children('option:selected').attr('value') == null && 
$(setSelector).length > 1)
   {
     thisElement.hide('normal', function () { thisElement.remove() } );
     // NOTE: rest of script executes before thisElement.remove is called due 
to hide('slow') delay!
   }
-  
+
   // If the last element is not blank, then add a new blank element
   var lastElement = $(setSelector).eq(($(setSelector).length)-1);
   if (lastElement.children('option:selected').attr('value') != null)
   {
-   
+
     // Clone lastElement and insert clone after lastElement (hidden)
     var newElement = lastElement.clone(true);
     newElement.css('display', 'none');
     newElement.insertAfter(lastElement);
-      
+
     // Fancy fade-in effect (ooh, ahh!)
     newElement.show('normal');
   }
-  
+
   // Build unique ids by appending array index (e.g. thisId0, thisId1, etc.)
-  $(setSelector).each(function(i) 
-  {
+  $(setSelector).each(function(i){
     // Remove trailing digits from "id" attribute and append array index
     var idRoot = this.id.trimTrailingDigits();
     this.id = idRoot + i.toString();
-    
-    // Remove already selected values
-    
   })
 }
 
@@ -64,19 +63,17 @@
 // selectboxes with class="multiInstance"
 var fullOptionList = new Array;
 Drupal.behaviors.addMultiInstanceSelect = function (context)
-{  
-  $('select.multiInstance').change(function(event)
-  {
+{
+  $('select.multiInstance').change(function(event){
     multiInstanceSelector($(this));
-       });
-       
-       // Store an array of intial options for each selectbox option list
-       $('select.multiInstance').each( function(i)
-       {
-         fullOptionList[this.name] = new Array;
-         for (var j=0; j<this.options.length; j++)
-         {
-           fullOptionList[this.name][j] = this.options[j].value;
-         }
-       });
+  });
+
+  // Store an array of intial options for each selectbox option list
+  $('select.multiInstance').each(function(i){
+    fullOptionList[this.name] = new Array;
+    for (var j=0; j<this.options.length; j++)
+    {
+      fullOptionList[this.name][j] = this.options[j].value;
+    }
+  });
 }


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to