Plugin Directory

Changeset 1974934


Ignore:
Timestamp:
11/15/2018 01:56:51 PM (7 years ago)
Author:
john ackers
Message:

changed dom alteration commands, autocommit added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ecampaign/branches/maintenance/public.js

    r1700887 r1974934  
    2929
    3030
    31 ecam.onClickSubmit = function (buttonElement, phpClass, phpMethod)
    32 {
    33   // check that we know where we are
    34   if (buttonElement == null)
    35   {
    36     alert('onClickSubmit(): clickable element not declared');
     31ecam.onClickSubmit = function (buttonElement, phpMethod)
     32{
     33  var button = jQuery(buttonElement);
     34  return ecam.submit(button, [], phpMethod);
     35};
     36
     37
     38ecam.submit = function(trigger, postData, phpMethod)
     39{
     40  // find the root of the form
     41  var formRoot = trigger.parents('form, .ecform');
     42  if (formRoot.length == 0)
     43  {
     44    alert('submit(): unable to find form wrapper');
    3745    return false;
    3846  }
    39   var button = jQuery(buttonElement);
    40   // find the root of the form
    41   var formRoot = button.parents('form, .ecform');
    42   if (formRoot.length == 0)
    43   {
    44     alert('onClickSubmit(): no form wrapper');
    45     return false;
    46   }
    47 
    4847  // find the closest element used to hold status messages
    49   var status = ecam.findClosestRelative(button, '.ecstatus');
     48  var status = jQuery(trigger).closestRelative('.ecstatus');
    5049  if (status.length == 0)
    5150  {
    52     alert('onClickSubmit(): status element not declared');
     51    alert('submit(): status element not declared');
    5352    return false;
    5453  }
     
    9291  // visitorName, visitorEmail, may have to be picked up from fields in adjacent form.
    9392
    94   var controlData = new Array();
    95  
    96   var recipient = formRoot.find('#recipients-email');
    97 
    98   controlData.push(   // and add fields wrapped in DIV tags
     93  var controlData = [   // and add fields wrapped in DIV tags
    9994    {  name :  'action',          value : 'ecampaign' },
    10095    {  name :  'formID',          value : formRoot.attr('id')},
    101     {  name :  'class',           value : phpClass },
    102     {  name :  'method',          value : phpMethod },
    103     {  name :  'recipientsEmail', value : ecam.removeAntiSpam(recipient) }   
    104   );
     96    {  name :  'method',          value : phpMethod }     
     97  ];
    10598
    10699  var primaryFormFields = formRoot.find("input, textarea").serializeArray();
    107   var secondaryFormFields = formRoot.siblings().find("input, textarea").serializeArray();
    108 
    109   var postData = ecam.mergeArraysSkippingDuplicateKeys(new Array(controlData, primaryFormFields, secondaryFormFields)); 
    110  
    111   // about to post to server...
    112 
     100
     101  var postData = ecam.mergeArraysSkippingDuplicateKeys(new Array(postData, controlData, primaryFormFields)); 
     102 
    113103  ecam.updateStatus(status,true,"waiting...");
    114104
     
    153143            switch(response.callbackJS)
    154144            {               // cannot work how to use JS introspection
    155               case  'updateMessageFields' :     ecam.updateMessageFields(response, button, formRoot); break;
    156               case  'revealVerificationField' : ecam.revealVerificationField(response, button, formRoot); break;              
    157               case  'revealForm' :              ecam.revealForm(response, button, formRoot); break; 
     145              case  'updateDOM' :     ecam.updateDOM(response, formRoot); break;           
     146              case  'revealForm' :    ecam.showElement(response, formRoot, true); break;   
     147              case  'hideForm' :      ecam.showElement(response, formRoot, false); break;
    158148            }
    159149          }
    160150          if (response.regexp != undefined)
    161             ecam.updateMessageBody(response.regexp, button, formRoot);
     151            ecam.updateMessageBody(response.regexp, formRoot);
    162152        }
    163153      }
     
    165155  });
    166156  return false; // suppress any other action
    167 };
    168 
    169 
    170 ecam.removeAntiSpam = function(selection)
    171 {
    172   var string = "";
    173   if (selection.length > 0)
    174     string = ecam.getNodeText(selection[0], string);
    175   return string ;
    176157};
    177158
     
    231212 */
    232213
    233 ecam.updateMessageBody = function (regexp, button, formRoot)
     214ecam.updateMessageBody = function (regexp, formRoot)
    234215
    235216  var body = formRoot.find("textarea[name='body']").first();
    236217  var currentText = body.val() ;  // may NOT be actually what has been keyed in
    237 
    238   var updatedText = currentText.replace(regexp.pattern, regexp.replacement);
     218  var pattern = (regexp.pattern) ? new RegExp(regexp.pattern) : regexp.search ;
     219  var updatedText = currentText.replace(pattern, regexp.replacement);
    239220 
    240221  if (updatedText != currentText)   // successful update
     
    253234    if (ecam.lastUpdatedText != undefined  && currentText == ecam.lastUpdatedText)
    254235    {
    255       updatedText = ecam.lastOriginalText.replace(regexp.pattern, regexp.replacement);
     236      updatedText = ecam.lastOriginalText.replace(pattern, regexp.replacement);
    256237      if (updatedText != ecam.lastOriginalText)
    257238      {
     
    260241      else
    261242      {
    262         alert("Unable to substitute " + regexp.pattern +  " with " + regexp.replacement);
     243        alert("Unable to substitute " + pattern +  " with " + regexp.replacement);
    263244        return ;         
    264245      }
     
    267248    {
    268249      alert("Message text may have been edited; " +
    269           " unable to substitute " + regexp.pattern + " with " + regexp.replacement +
     250          " unable to substitute " + pattern + " with " + regexp.replacement +
    270251          ". Please check the message text before sending.");
    271252      return ;
     
    291272
    292273
    293 ecam.updateMessageFields = function (response, button, formRoot)
     274ecam.updateDOM = function (response, formRoot)
    294275
     276 /*
    295277  var names="", emails="", num=0 ;
    296278
     
    308290    formRoot.find("#recipients-email").html(names);
    309291  }
    310 
     292*/
     293  if (response.updates != undefined && response.updates instanceof Object)
     294  {
     295    for (x in response.updates)
     296    {
     297      var update = response.updates[x];
     298      var root = update.selector != undefined ? jQuery(formRoot) : jQuery();
     299      var target = root.closestRelative(update.selector) ;
     300
     301      if (target.length == 0)
     302      {
     303        alert("Target has no matching elements"); return ;
     304      }
     305      if (update.val != undefined)
     306        target.val(update.val);    // input fields
     307      if (update.text != undefined)
     308        target.text(update.text);  // (encoded) div and textarea
     309      if (update.html != undefined)
     310        target.html(update.html);
     311      if (update.checked != undefined)
     312      {
     313        if (target.attr('type') != 'checkbox')
     314          alert('Cannot (un)set checkbox');
     315         target.prop('checked', update.checked);
     316      }
     317    }
     318  } 
     319  /*
     320  if (response.targetEmail != undefined)
     321    formRoot.find("#recipients-email").html(response.targetEmail)
     322 
    311323  if (response.targetSubject != undefined)
    312324    formRoot.find("input[name='subject']").attr('value',response.targetSubject);
     
    314326  if (response.targetBody != undefined)
    315327    formRoot.find("textarea[name='body']").html(response.targetBody);
     328  */
    316329 
    317330  submitButton = formRoot.find(".ecsend input");
     
    319332};
    320333
    321 
    322 ecam.findClosestRelative = function (elements, select)
    323 
    324   var parents = elements.parents();
    325   for (var i=0 ; i < parents.length ; i++)
    326   {
    327     var cousins = jQuery(parents[i]).find(select);
    328     if (cousins.length > 0)
    329       return cousins.first();
    330   }
    331   return jQuery();  // returns an empty set
    332 };
    333 
    334 
    335 /**
    336  * called back when email send to target
    337  * @param button (jQuery) clicked by user
    338  */
    339 
    340 ecam.revealVerificationField = function (response, button, formRoot)
    341 {   
    342   if (response.success)
    343   {   
    344     formRoot.find('.eccode').show('slow');
    345   }
    346 };
    347    
    348    
    349 ecam.revealForm = function (response, button, formRoot)
    350 {   
    351   var nextForm ;
    352   if (response.success)
    353   {   
    354     button.attr("disabled","disabled");   // prevent user from trying to sending two messages
    355     if (response.selector == undefined)
    356       nextForm = formRoot.siblings();     // default is to reveal all forms
    357     else
    358       nextForm = jQuery(response.selector);
    359 //    nextForm.show('slow');                // the friends form is enabled, now show it
    360       nextForm.removeClass('hidden');       // ja 23-nov-2015
    361   }
    362 };
    363 
    364 /**
    365  * merge all the arrays of name, value pair objects contained in array s
     334   
     335ecam.showElement = function (response, item, display)
     336{
     337  if (response.success && response.selector != undefined)
     338    display ? jQuery(response.selector).slideDown(1000) : jQuery(response.selector).slideUp(1000);
     339}
     340
     341/**
     342 * merge all the arrays of jQuery type name, value pair objects contained in array s
    366343 * into single array.  Ignore objects with duplicate keys.
    367344 */
     
    463440
    464441
    465 
     442jQuery.fn.extend({ 
     443  closestRelative : function(select) { return this.genealogy(select).relative },
     444  commonAncestor  : function(select) { return this.genealogy(select).ancestor }, 
     445  genealogy : function(select)
     446  {
     447    for (var parent = this.get(0); parent ; parent = parent.parentNode)
     448    {
     449      var jqParent = jQuery(parent);
     450      var cousins = jqParent.find(select);
     451      if (cousins.length > 0)
     452        return { relative : cousins.first(), ancestor : jqParent.first()};
     453    }
     454    return { relative : jQuery(), ancestor : jQuery() };  // returns an empty set
     455  },
     456  serializeToObject : function(query)
     457  {
     458    var ar = this.serializeArray();
     459    for (var i in ar)
     460      query[ar[i].name] = ar[i].value ;
     461    return query ;
     462  }
     463});
    466464
    467465jQuery(document).ready(function() {
     466
    468467 
    469468  jQuery(".ecinputwrap input[type='text']").each(function(index, element)
     
    479478        return true ;
    480479      }
    481   ); 
     480  );
     481  var form0 = jQuery('.ec-target');
     482  var form = jQuery('.ec-target').has("input[name='autoSubmit']");
     483  var item = form.find('.autoSubmit');
     484  if (item.length && item.get(0).value.length)
     485    // trigger an auto submit of form with supplied verification code.
     486    ecam.submit(item, [], "verify");
     487 
    482488  /**
    483    * when the use updates an input field, copy it to any other input fields
     489   * when the user updates an input field, copy it to any other input fields
    484490   * of the same name to reduce rekeying.
    485491   */
    486  
     492/* 
    487493  jQuery(".ecinputwrap input[type='text']").change(
    488494     
     
    500506      }
    501507  );
     508  */
    502509});
     510
     511
Note: See TracChangeset for help on using the changeset viewer.