protected static function get_control_customJS($auth, $args, $tabalias, $options)
 {
     if (lang::get('validation_required') != 'validation_required') {
         data_entry_helper::$late_javascript .= "\r\n\$.validator.messages.required = \"" . lang::get('validation_required') . "\";";
     }
     if (lang::get('validation_max') != 'validation_max') {
         data_entry_helper::$late_javascript .= "\r\n\$.validator.messages.max = \$.validator.format(\"" . lang::get('validation_max') . "\");";
     }
     if (lang::get('validation_min') != 'validation_min') {
         data_entry_helper::$late_javascript .= "\r\n\$.validator.messages.min = \$.validator.format(\"" . lang::get('validation_min') . "\");";
     }
     if (lang::get('validation_number') != 'validation_number') {
         data_entry_helper::$late_javascript .= "\r\n\$.validator.messages.number = \$.validator.format(\"" . lang::get('validation_number') . "\");";
     }
     if (lang::get('validation_digits') != 'validation_digits') {
         data_entry_helper::$late_javascript .= "\r\n\$.validator.messages.digits = \$.validator.format(\"" . lang::get('validation_digits') . "\");";
     }
     // possible clash with link_species_popups, so latter disabled.
     iform_mnhnl_addCancelButton($args['interface']);
     data_entry_helper::$javascript .= "\r\nresetChildValue = function(child){\r\n  var options = child.find('option').not('[value=]').not('[disabled]');\r\n  if (options.length==1)\r\n    child.val(options.val());\r\n  else child.val('');\r\n};\r\nset_up_relationships = function(startAttr, parent, setval){\r\n  start=false; // final field is treated differently, as it enforces no duplicates.\r\n  myParentRow = jQuery(parent).closest('tr');\r\n  for(var i=0; i < attrRestrictionsProcessOrder.length-1; i++){\r\n    if(start || startAttr==attrRestrictionsProcessOrder[i]){\r\n      start=true;\r\n      var child = myParentRow.find('[name\$=occAttr\\:'+attrRestrictionsProcessOrder[i]+'],[name*=occAttr\\:'+attrRestrictionsProcessOrder[i]+'\\:]');\r\n      var childOptions = child.find('option').not('[value=]');\r\n      resetChild=false;\r\n      if(parent.val() == '') {\r\n        childOptions.attr('disabled','disabled');\r\n        if(setval) resetChild=true;\r\n      } else {\r\n        childOptions.attr('disabled','');\r\n        for(var j=0; j < relationships.length; j++){\r\n          if(relationships[j].child == attrRestrictionsProcessOrder[i]){\r\n            var relParentVal = jQuery(parent).closest('tr').find('[name\$=occAttr\\:'+relationships[j].parent+'],[name*=occAttr\\:'+relationships[j].parent+'\\:]').val();\r\n            for(var k=0; k < relationships[j].values.length; k++){\r\n              if(relParentVal == relationships[j].values[k].value) {\r\n                childOptions.each(function(index, Element){\r\n                  for(var m=0; m < relationships[j].values[k].list.length; m++){\r\n                    if(relationships[j].values[k].list[m] == \$(this).val()){\r\n                      \$(this).attr('disabled','disabled');\r\n                      if(\$(this).val() == child.val() && setval) resetChild=true;\r\n                    }}\r\n                  });\r\n              }}}}\r\n       }\r\n       if(child.val()=='' && setval) resetChild=true;\r\n       if(resetChild) resetChildValue(child);\r\n    }\r\n  }\r\n  // something has changed: now need to go through ALL rows final field, not just ours, and eliminate options which would cause a duplicate.\r\n  // but some of those may have been re-added by the change so have to reset all options!\r\n  i= attrRestrictionsProcessOrder.length-1;\r\n  var tableRows = jQuery(parent).closest('table').find('.scDataRow');\r\n  tableRows.each(function(index, Row){\r\n    var child = jQuery(Row).find('[name\$=occAttr\\:'+attrRestrictionsProcessOrder[i]+'],[name*=occAttr\\:'+attrRestrictionsProcessOrder[i]+'\\:]');\r\n    var parent = jQuery(Row).find('[name\$=occAttr\\:'+attrRestrictionsProcessOrder[i-1]+'],[name*=occAttr\\:'+attrRestrictionsProcessOrder[i-1]+'\\:]');\r\n    var childOptions = child.find('option').not('[value=]');\r\n    resetChild=false;\r\n    if(parent.val() == '') {\r\n      childOptions.attr('disabled','disabled'); // all disabled.\r\n      if(setval && myParentRow[0]==Row) resetChild=true;\r\n    } else {\r\n      childOptions.attr('disabled','');\r\n      for(var j=0; j < relationships.length; j++){\r\n        if(relationships[j].child == attrRestrictionsProcessOrder[i]){\r\n          var relParentVal = jQuery(Row).find('[name\$=occAttr\\:'+relationships[j].parent+'],[name*=occAttr\\:'+relationships[j].parent+'\\:]').val();\r\n          for(var k=0; k < relationships[j].values.length; k++){\r\n            if(relParentVal == relationships[j].values[k].value) {\r\n              childOptions.each(function(index, Element){\r\n                for(var m=0; m < relationships[j].values[k].list.length; m++){\r\n                  if(relationships[j].values[k].list[m] == \$(Element).val()){\r\n                    \$(Element).attr('disabled','disabled');\r\n                    if(\$(Element).val() == child.val() && setval && myParentRow[0]==Row) resetChild=true;\r\n                }}\r\n              });\r\n    }}}}}\r\n    // now check duplicates\r\n    var classList = jQuery(Row).attr('class').split(/\\s+/);\r\n    jQuery.each( classList, function(index, item){ \r\n      var parts= item.split(/-/);\r\n      if(parts[0]=='scMeaning'){\r\n        sameSpeciesRows=jQuery('.'+item).not(Row);\r\n        sameSpeciesRows.each(function(index, sameSpeciesRow){\r\n          var same=true;\r\n          for(var j=0; j < attrRestrictionsProcessOrder.length-1; j++){\r\n            otherVal = jQuery(sameSpeciesRow).find('[name\$=occAttr\\:'+attrRestrictionsProcessOrder[j]+'],[name*=occAttr\\:'+attrRestrictionsProcessOrder[j]+'\\:]').val();\r\n            myVal = jQuery(Row).find('[name\$=occAttr\\:'+attrRestrictionsProcessOrder[j]+'],[name*=occAttr\\:'+attrRestrictionsProcessOrder[j]+'\\:]').val();\r\n            if(myVal == '' || otherVal == '' || myVal != otherVal) same=false;\r\n          }\r\n          myVal = jQuery(Row).find('[name\$=occAttr\\:'+attrRestrictionsProcessOrder[attrRestrictionsProcessOrder.length-1]+'],[name*=occAttr\\:'+attrRestrictionsProcessOrder[attrRestrictionsProcessOrder.length-1]+'\\:]').val();\r\n          otherVal = jQuery(sameSpeciesRow).find('[name\$=occAttr\\:'+attrRestrictionsProcessOrder[attrRestrictionsProcessOrder.length-1]+'],[name*=occAttr\\:'+attrRestrictionsProcessOrder[attrRestrictionsProcessOrder.length-1]+'\\:]').val();\r\n          // where all the other parents in the relationships are the same on this row, and the value is not empty\r\n          // and we have changed a value in a row (ie myParentRow), then that row is the one that gets reset if a duplicate row is created.\r\n          // ie myParentRow is one that will have option removed, not Row\r\n          if(same && (myVal!=otherVal || myParentRow[0]!=sameSpeciesRow)){\r\n            if(otherVal!='')\r\n              childOptions.filter('[value='+otherVal+']').attr('disabled','disabled');\r\n            if(setval && otherVal == child.val())\r\n              resetChild=true;\r\n          }\r\n        });\r\n      }\r\n    });\r\n    if(child.val()=='' && setval && myParentRow[0]==Row) resetChild=true;\r\n    if(resetChild) resetChildValue(child);\r\n  });\r\n};\r\n\r\n   /*\r\n     * @attrRestrictions=\r\n24:25:231,235:232,235,236,237:234,235,236,237;\r\n25:26:235,239,240,241:236,241:238,239,240,241;\r\n24:27:231,243,244,245,246,247,248,249,250,251,252,253;\r\n25:27:235,243,244,245,246,247,248,249,250,251,252,253:236,244,250,251;\r\n26:27:240,251:239,244:242,244,251\r\n     */\r\nrelationships = [";
     if (isset($options["attrRestrictions"]) && $options["attrRestrictions"] != "") {
         $restrictionRules = explode(';', $options["attrRestrictions"]);
         foreach ($restrictionRules as $restrictionRule) {
             $parts = explode(':', $restrictionRule);
             data_entry_helper::$javascript .= "{parent : " . $parts[0] . ",\r\n  child : " . $parts[1] . ",\r\n  values: [";
             for ($i = 2; $i < count($parts); $i++) {
                 $values = explode(',', trim($parts[$i]));
                 data_entry_helper::$javascript .= "{value : " . $values[0] . ", list: [\"";
                 unset($values[0]);
                 data_entry_helper::$javascript .= implode("\",\"", $values) . "\"]},\r\n          ";
             }
             data_entry_helper::$javascript .= "]},";
         }
     }
     data_entry_helper::$javascript .= "\r\n];";
     if (isset($options["attrRestrictionsProcessOrder"]) && $options["attrRestrictionsProcessOrder"] != "") {
         $attrOrder = explode(':', $options["attrRestrictionsProcessOrder"]);
         data_entry_helper::$javascript .= "\r\nattrRestrictionsProcessOrder = [" . implode(',', $attrOrder) . "];\r\n// set up pre-existing ones.\r\njQuery('[name\$=occAttr\\:" . $attrOrder[0] . "],[name*=occAttr\\:" . $attrOrder[0] . "\\:]').each(function(){\r\n    set_up_relationships(" . $attrOrder[1] . ", \$(this), false);\r\n});";
         // need to check all but last
         for ($i = 0; $i < count($attrOrder) - 1; $i++) {
             data_entry_helper::$javascript .= "\r\njQuery('[name\$=occAttr\\:" . $attrOrder[$i] . "],[name*=occAttr\\:" . $attrOrder[$i] . "\\:]').live('change',\r\n  function(){\r\n    set_up_relationships(" . $attrOrder[$i + 1] . ", \$(this), true);\r\n  });";
         }
         // last is special - only updates similar on other rows.
         data_entry_helper::$javascript .= "\r\njQuery('[name\$=occAttr\\:" . $attrOrder[count($attrOrder) - 1] . "],[name*=occAttr\\:" . $attrOrder[count($attrOrder) - 1] . "\\:]').live('change',\r\n  function(){\r\n    var parent = \$(this).closest('tr').find('[name\$=occAttr\\:" . $attrOrder[count($attrOrder) - 2] . "],[name*=occAttr\\:" . $attrOrder[count($attrOrder) - 2] . "\\:]');\r\n    set_up_relationships(" . $attrOrder[count($attrOrder) - 1] . ", parent, true);\r\n  });";
     }
     if (!empty($args['attributeValidation'])) {
         $rules = array();
         $argRules = explode(';', $args['attributeValidation']);
         foreach ($argRules as $rule) {
             $rules[] = explode(',', $rule);
         }
         foreach ($rules as $rule) {
             // But only do if a parameter given as rule:param - eg min:-40
             for ($i = 1; $i < count($rule); $i++) {
                 if (strpos($rule[$i], ':') !== false) {
                     $details = explode(':', $rule[$i]);
                     data_entry_helper::$late_javascript .= "\r\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').attr('" . $details[0] . "'," . $details[1] . ");";
                 } else {
                     if ($rule[$i] == 'no_observation') {
                         data_entry_helper::$late_javascript .= "\r\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').filter(':checkbox').rules('add', {no_observation: true});\r\nhook_check_no_obs=function() {\r\n  if(jQuery('.scPresence').filter(':checkbox').filter('[checked]').length==0)\r\n    jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').removeAttr('disabled');\r\n  else\r\n    jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').filter(':checkbox').attr('disabled','disabled').removeAttr('checked');\r\n};\r\nhook_check_no_obs();\r\n\$.validator.addMethod('no_observation', function(arg1, arg2){\r\n  var numRows = jQuery('.scPresence').filter(':checkbox').filter('[checked]').length;\r\n  var isChecked = jQuery('[name='+jQuery(arg2).attr('name')+']').not(':hidden').filter('[checked]').length>0;\r\n  if(isChecked) return(numRows==0)\r\n  else if(numRows>0) return true;\r\n  // Not checked, no rows: ensure no obs can be filled in, and flag failure.\r\n  jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').removeAttr('disabled');\r\n  // this is being used against a boolean checkbox, which has a hidden zero field before. Have to tag on to later field explicitly.\r\n  return false;\r\n},\r\n  \"" . lang::get('validation_no_observation') . "\");\r\n";
                     } else {
                         if ($rule[$i] == 'no_record') {
                             data_entry_helper::$late_javascript .= "\r\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').rules('add', {no_record: true});\r\n\$.validator.addMethod('no_record', function(arg1, elem){\r\n  // validation for radio buttons only called for selected one.\r\n  var numRows = jQuery('.scPresence').filter(':checkbox').filter('[checked]').length;\r\n  var rbutton = jQuery('[name='+jQuery(elem).attr('name')+']').eq(0).filter('[checked]').length>0;\r\n  if((numRows>0 && rbutton)||(numRows==0 && !rbutton)) return true;\r\n  return false;\r\n},\r\n  \"" . lang::get('validation_no_record') . "\");\r\n";
                         } else {
                             if (substr($rule[0], 3, 4) != 'Attr') {
                                 // have to add for non attribute case.
                                 data_entry_helper::$late_javascript .= "\r\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').addClass('" . $rule[$i] . "');";
                             }
                         }
                     }
                 }
             }
         }
     }
     return '';
 }
 public static function get_form($args, $node, $response = null)
 {
     global $indicia_templates;
     global $user;
     $indicia_templates['select_item'] = '<option value="{value}" {selected} >{caption}&nbsp;</option>';
     if ($user->uid === 0) {
         return lang::get('Before using this facility, please <a href="' . url('user/login', array('query' => 'destination=node/' . $node->nid)) . '">login</a> to the website.');
     }
     // we don't use the map, but a lot of the inherited code assumes the map is present.
     self::$svcUrl = data_entry_helper::$base_url . '/index.php/services';
     data_entry_helper::add_resource('openlayers');
     $indicia_templates['label'] = '<label for="{id}"{labelClass}>{label}:</label>';
     // can't have the CR on the end
     $indicia_templates['zilch'] = '';
     // can't have the CR on the end
     self::$locations = iform_loctools_listlocations($node);
     $retVal = parent::get_form($args, $node, $response);
     if (parent::$mode != self::MODE_GRID) {
         iform_mnhnl_addCancelButton($args['interface']);
         data_entry_helper::$javascript .= "\n\$.validator.messages.required = \"" . lang::get('validation_required') . "\";";
         if (!iform_loctools_checkaccess($node, 'superuser')) {
             data_entry_helper::$javascript .= "\njQuery('[name=smpAttr\\:" . $args['observer_attr_id'] . "],[name^=smpAttr\\:" . $args['observer_attr_id'] . "\\:]').attr('readonly',true)";
             if (parent::$mode == self::MODE_NEW) {
                 data_entry_helper::$javascript .= ".val(\"" . $user->name . "\");";
             } else {
                 data_entry_helper::$javascript .= ";";
             }
         } else {
             $userlist = iform_loctools_listusers($node);
             data_entry_helper::$javascript .= "\nexisting = jQuery('[name=smpAttr\\:" . $args['observer_attr_id'] . "],[name^=smpAttr\\:" . $args['observer_attr_id'] . "\\:]');\nreplacement = '<select name=\"'+existing.attr('name')+'\" >";
             foreach ($userlist as $uid => $a_user) {
                 data_entry_helper::$javascript .= "<option value=\"" . $a_user->name . "\">" . $a_user->name . "&nbsp;</option>";
             }
             data_entry_helper::$javascript .= "</select>';\njQuery(replacement).insertBefore(existing).val(existing.val());\nexisting.remove();\n";
         }
         data_entry_helper::$javascript .= "\n// jQuery('#sample\\\\:date').datepicker( \"option\", \"minDate\", new Date(2010, 4 - 1, 1) );\nDate.prototype.getMonthName = function() {\nvar m = ['" . lang::get('January') . "','" . lang::get('February') . "','" . lang::get('March') . "',\n'" . lang::get('April') . "','" . lang::get('May') . "','" . lang::get('June') . "',\n'" . lang::get('July') . "','" . lang::get('August') . "','" . lang::get('September') . "',\n'" . lang::get('October') . "','" . lang::get('November') . "','" . lang::get('December') . "'];\nreturn m[this.getMonth()];\n} \nvar monthAttr = jQuery('[name=smpAttr\\\\:" . $args['month_attr_id'] . "],[name^=smpAttr\\\\:" . $args['month_attr_id'] . "\\\\:]').attr('disabled', true);\nmonthAttr.before('<input type=\"hidden\" id=\"storedMonth\" name=\"'+monthAttr.attr('name')+'\">');\nupdateSampleDate = function(context, doAlert){\n  jQuery('.displayDateDetails').empty().append('<span>'+jQuery('[name=sample\\:date]').val()+'</span>');\n  var myDate = jQuery(context).datepicker(\"getDate\");\n  var monthAttr = jQuery('[name=smpAttr\\\\:" . $args['month_attr_id'] . "],[name^=smpAttr\\\\:" . $args['month_attr_id'] . "\\\\:]').filter('select').val('');\n  if(myDate != null){\n    myDate = myDate.getMonthName();\n    monthAttr.find(\"option:contains('\"+myDate+\"')\").attr('selected',true) ; \n    jQuery('#storedMonth').val(monthAttr.val()); // doing in this order converts the text to a number and stores that number in the storedMonth\n  } else\n    jQuery('#storedMonth').val('');\n  if(doAlert && monthAttr.val() == \"\")\n  \talert('Given date is outside valid month range (April to September).');\n};\njQuery('#sample\\\\:date').change(function(){updateSampleDate(this, true);});\nupdateSampleDate('#sample\\\\:date', false);\njQuery('.tab-submit').unbind('click');\njQuery('.tab-submit').click(function() {\n  var current=jQuery('#controls').tabs('option', 'selected');\n  var tabinputs = jQuery('#entry_form div > .ui-tabs-panel:eq('+current+')').find('input,select');\n  var secList = '';\n  if (!tabinputs.valid()) { return; }\n  var rows = jQuery('.sectionlist').find('tr');\n  for(var i=1; i<= " . $args['max_number_sections'] . "; i++){\n    if(jQuery('.sectionlist').find('[section='+i+']').length > 0) {\n      var aucuneControl = jQuery(':checkbox[name^=\"SLA\\:'+i+'\\:\"]').filter('[name\$=\"\\:" . $args['aucune_attr_id'] . "\"]');\n      var foundEntry = false;\n      for(var j = 1; j < (rows.length-(numAttrs+1)); j++){\n        foundEntry = foundEntry || (jQuery(rows[j]).find('td').filter(':eq('+i+')').find('[value!=\"\"]').length > 0);\n      }\n      if(!foundEntry && !aucuneControl.attr('checked')){\n          secList = secList + (secList=='' ? '' : ', ') + i;\n      }\n    }\n  }\n  if (secList != ''){\n    alert('The following sections have no species recorded against them: Section(s) '+secList+'. In these circumstances, the \"No observation\" checkbox must be checked for the relevant section.'); \n    return;\n  }\n  var form = jQuery(this).parents('form:first');\n  form.submit();\n});\n";
     } else {
         $retVal .= "<div style=\"display:none\" />\n    <form id=\"form-delete-survey\" action=\"" . iform_mnhnl_getReloadPath() . "\" method=\"POST\">" . parent::$auth['write'] . "\n       <input type=\"hidden\" name=\"website_id\" value=\"" . $args['website_id'] . "\" />\n       <input type=\"hidden\" name=\"survey_id\" value=\"" . $args['survey_id'] . "\" />\n       <input type=\"hidden\" name=\"sample:id\" value=\"\" />\n       <input type=\"hidden\" name=\"sample:date\" value=\"2010-01-01\"/>\n       <input type=\"hidden\" name=\"sample:location_id\" value=\"\" />\n       <input type=\"hidden\" name=\"sample:deleted\" value=\"t\" />\n    </form>\n</div>";
         data_entry_helper::$javascript .= "\ndeleteSurvey = function(sampleID){\n  if(confirm(\"Are you sure you wish to delete survey \"+sampleID)){\n    jQuery.getJSON(\"" . self::$svcUrl . "/data/sample/\"+sampleID +\n            \"?mode=json&view=detail&auth_token=" . parent::$auth['read']['auth_token'] . "&nonce=" . parent::$auth['read']["nonce"] . "\" +\n            \"&callback=?\", function(data) {\n        if (data.length>0) {\n          jQuery('#form-delete-survey').find('[name=sample\\:id]').val(data[0].id);\n          jQuery('#form-delete-survey').find('[name=sample\\:date]').val(data[0].date_start);\n          jQuery('#form-delete-survey').find('[name=sample\\:location_id]').val(data[0].location_id);\n          jQuery('#form-delete-survey').submit();\n  }});\n  };\n};\n";
     }
     return $retVal;
 }
Example #3
0
 /**
  * Insert any custom JS for this form: this may be related to attributes, which are included
  * as part of inherited generic code.
  * Does not include any HTML.
  */
 protected static function get_control_customJS($auth, $args, $tabalias, $options)
 {
     if (lang::get('validation_required') != 'validation_required') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.required = \"" . lang::get('validation_required') . "\";";
     }
     if (lang::get('validation_max') != 'validation_max') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.max = \$.validator.format(\"" . lang::get('validation_max') . "\");";
     }
     if (lang::get('validation_min') != 'validation_min') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.min = \$.validator.format(\"" . lang::get('validation_min') . "\");";
     }
     if (lang::get('validation_number') != 'validation_number') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.number = \$.validator.format(\"" . lang::get('validation_number') . "\");";
     }
     if (lang::get('validation_digits') != 'validation_digits') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.digits = \$.validator.format(\"" . lang::get('validation_digits') . "\");";
     }
     if (lang::get('validation_integer') != 'validation_integer') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.integer = \$.validator.format(\"" . lang::get('validation_integer') . "\");";
     }
     iform_mnhnl_addCancelButton($args['interface']);
     $r .= self::getSiteTypeJS(parent::$auth, $args);
     data_entry_helper::$javascript .= "\nif(\$.browser.msie && \$.browser.version < 9)\n  \$('input[type=radio],[type=checkbox]').live('click', function(){\n    this.blur();\n    this.focus();\n});\n";
     // Move the date after the Institution
     $institutionAttrID = iform_mnhnl_getAttrID($auth, $args, 'sample', 'Institution');
     if ($institutionAttrID) {
         data_entry_helper::$javascript .= "\nvar institutionAttr = jQuery('[name=smpAttr\\:" . $institutionAttrID . "],[name^=smpAttr\\:" . $institutionAttrID . "\\:],[name^=smpAttr\\:" . $institutionAttrID . "\\[\\]]').not(':hidden').eq(0).closest('.control-box').next();\nvar recorderField = jQuery('#sample\\\\:recorder_names');\nvar recorderLabel = recorderField.prev().filter('label');\nvar recorderRequired = recorderField.next();\nrecorderRequired.next().filter('br').remove();\nvar recorderText = recorderRequired.next();\nrecorderText.next().filter('br').remove();\nrecorderText.next().filter('br').remove();\ninstitutionAttr.after('<br/>');\ninstitutionAttr.after('<br/>');\ninstitutionAttr.after(recorderText);\ninstitutionAttr.after('<br/>');\ninstitutionAttr.after(recorderRequired);\ninstitutionAttr.after(recorderField);\ninstitutionAttr.after(recorderLabel);\nvar dateField = jQuery('#sample\\\\:date');\nvar dateLabel = dateField.prev().filter('label');\nvar dateRequired = dateField.next();\ndateRequired.next().filter('br').remove();\ninstitutionAttr.after('<br/>');\ninstitutionAttr.after(dateRequired);\ninstitutionAttr.after(dateField);\ninstitutionAttr.after(dateLabel);\n";
     }
     // Break up the Disturbances: makes assumptions on format, and assumes that we are doing a checkbox list
     if (!empty($args['addBreaks'])) {
         $addBreakSpecs = explode(';', $args['addBreaks']);
         foreach ($addBreakSpecs as $addBreakSpec) {
             $addBreakDetail = explode(',', $addBreakSpec);
             $addBreakDetail[0] = str_replace(':', '\\:', $addBreakDetail[0]);
             data_entry_helper::$javascript .= "jQuery('[name^=" . $addBreakDetail[0] . "\\:],[name^=" . $addBreakDetail[0] . "\\[\\]]').filter('[value=" . $addBreakDetail[1] . "],[value^=" . $addBreakDetail[1] . "\\:]').parent().before('<br/>');\n";
         }
     }
     $disturbOtherAttrID = iform_mnhnl_getAttrID($auth, $args, 'sample', 'Disturbances other comment');
     if (!$disturbOtherAttrID) {
         return lang::get('This form must be used with a survey that has the Disturbances other comment attribute associated with it.');
     }
     $disturb2AttrID = iform_mnhnl_getAttrID($auth, $args, 'sample', 'Disturbances2');
     if (!$disturb2AttrID) {
         return lang::get('This form must be used with a survey that has the Disturbances2 attribute associated with it.');
     }
     $disturb2OtherTerm = helper_base::get_termlist_terms($auth, 'bats2:disturbances', array('Other'));
     $disturb2PlannedTerm = helper_base::get_termlist_terms($auth, 'bats2:disturbances', array('Planned renovations'));
     $disturb2InProgTerm = helper_base::get_termlist_terms($auth, 'bats2:disturbances', array('Renovations in progress'));
     $disturb2RecentTerm = helper_base::get_termlist_terms($auth, 'bats2:disturbances', array('Renovations recently completed'));
     data_entry_helper::$javascript .= "\njQuery('[name=smpAttr\\:" . $disturb2AttrID . "\\[\\]],[name^=smpAttr\\:" . $disturb2AttrID . "\\:]').filter('[value=" . $disturb2PlannedTerm[0]['meaning_id'] . "],[value^=" . $disturb2PlannedTerm[0]['meaning_id'] . "\\:]').change(function(){\n  if(this.checked)\n    jQuery('[name=smpAttr\\:" . $disturb2AttrID . "\\[\\]],[name^=smpAttr\\:" . $disturb2AttrID . "\\:]').filter('[value=" . $disturb2InProgTerm[0]['meaning_id'] . "],[value^=" . $disturb2InProgTerm[0]['meaning_id'] . "\\:],[value=" . $disturb2RecentTerm[0]['meaning_id'] . "],[value^=" . $disturb2RecentTerm[0]['meaning_id'] . "\\:]').removeAttr('checked');\n});\njQuery('[name=smpAttr\\:" . $disturb2AttrID . "\\[\\]],[name^=smpAttr\\:" . $disturb2AttrID . "\\:]').filter('[value=" . $disturb2InProgTerm[0]['meaning_id'] . "],[value^=" . $disturb2InProgTerm[0]['meaning_id'] . "\\:]').change(function(){\n  if(this.checked)\n    jQuery('[name=smpAttr\\:" . $disturb2AttrID . "\\[\\]],[name^=smpAttr\\:" . $disturb2AttrID . "\\:]').filter('[value=" . $disturb2PlannedTerm[0]['meaning_id'] . "],[value^=" . $disturb2PlannedTerm[0]['meaning_id'] . "\\:],[value=" . $disturb2RecentTerm[0]['meaning_id'] . "],[value^=" . $disturb2RecentTerm[0]['meaning_id'] . "\\:]').removeAttr('checked');\n});\njQuery('[name=smpAttr\\:" . $disturb2AttrID . "\\[\\]],[name^=smpAttr\\:" . $disturb2AttrID . "\\:]').filter('[value=" . $disturb2RecentTerm[0]['meaning_id'] . "],[value^=" . $disturb2RecentTerm[0]['meaning_id'] . "\\:]').change(function(){\n  if(this.checked)\n    jQuery('[name=smpAttr\\:" . $disturb2AttrID . "\\[\\]],[name^=smpAttr\\:" . $disturb2AttrID . "\\:]').filter('[value=" . $disturb2InProgTerm[0]['meaning_id'] . "],[value^=" . $disturb2InProgTerm[0]['meaning_id'] . "\\:],[value=" . $disturb2PlannedTerm[0]['meaning_id'] . "],[value^=" . $disturb2PlannedTerm[0]['meaning_id'] . "\\:]').removeAttr('checked');\n});\nvar myTerm = jQuery('[name=smpAttr\\:" . $disturb2AttrID . "\\[\\]],[name^=smpAttr\\:" . $disturb2AttrID . "\\:]').filter('[value=" . $disturb2OtherTerm[0]['meaning_id'] . "],[value^=" . $disturb2OtherTerm[0]['meaning_id'] . "\\:]');\nmyTerm.change(function(){\n    if(this.checked)\n      jQuery('[name=smpAttr\\:" . $disturbOtherAttrID . "],[name^=smpAttr\\:" . $disturbOtherAttrID . "\\:]').addClass('required').removeAttr('readonly');\n    else\n      jQuery('[name=smpAttr\\:" . $disturbOtherAttrID . "],[name^=smpAttr\\:" . $disturbOtherAttrID . "\\:]').removeClass('required').val('').attr('readonly',true);\n  });\nvar other = jQuery('[name=smpAttr\\:" . $disturbOtherAttrID . "],[name^=smpAttr\\:" . $disturbOtherAttrID . "\\:]');\nother.next().remove(); // remove break\nother.prev().remove(); // remove legend\nother.removeClass('wide').remove(); // remove Other field, then bolt in after the other radio button.\nmyTerm.parent().append(other);\nmyTerm.change();\njQuery('span').filter('.control-box').each(function(idex, elem){\n  if(jQuery(elem).find(':checkbox').length){\n    jQuery(elem).prev().filter('label').addClass('auto-width');\n    jQuery(elem).prev().after('<br/>');\n  }\n});\n";
     if (!empty($args['attributeValidation'])) {
         $rules = array();
         $argRules = explode(';', $args['attributeValidation']);
         foreach ($argRules as $rule) {
             $rules[] = explode(',', $rule);
         }
         foreach ($rules as $rule) {
             // But only do if a parameter given as rule:param - eg min:-40
             for ($i = 1; $i < count($rule); $i++) {
                 if (strpos($rule[$i], ':') !== false) {
                     $details = explode(':', $rule[$i]);
                     data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').attr('" . $details[0] . "'," . $details[1] . ");";
                 } else {
                     if ($rule[$i] == 'no_record') {
                         data_entry_helper::$late_javascript .= "\nnoRecCheckbox = jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').filter(':checkbox');\nnumRows = jQuery('.scPresence').filter('[value=1]').length;\nif(numRows>0)\n  noRecCheckbox.addClass('no_record').removeAttr('checked').attr('disabled','disabled');\nelse\n  noRecCheckbox.addClass('no_record').removeAttr('disabled');\n";
                     } else {
                         if (substr($rule[0], 3, 4) != 'Attr') {
                             // have to add for non attribute case.
                             data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').addClass('" . $rule[$i] . "');";
                         }
                     }
                 }
             }
         }
     }
     data_entry_helper::$late_javascript .= "// JS for survey methods grid control.\n\$.validator.addMethod('method-presence', function(value, element){\n    var valid = jQuery('.method-presence').filter('[checked]').length > 0;\n\tif(valid){\n\t  jQuery('.method-presence').removeClass('ui-state-error').next('p.inline-error').remove();\n\t}\n\treturn valid;\n},\n  \"" . lang::get('validation_method-presence') . "\");\n\$.validator.addMethod('scNumDead', function(value, element){\n  var assocNumAlive = jQuery(element).closest('tr').find('.scNumAlive');\n  var valid = true;\n  if(jQuery(element).val()!='' || assocNumAlive.val()!='') {\n    valid = ((jQuery(element).val()=='' ? 0 : jQuery(element).val()) + (assocNumAlive.val()=='' ? 0 : assocNumAlive.val()) > 0);\n  }\n  if(valid){\n    assocNumAlive.removeClass('ui-state-error')\n  } else {\n    assocNumAlive.addClass('ui-state-error')\n  }\n  return valid;\n},\n  \"" . lang::get('validation_scNumDead') . "\");\njQuery('.scNumAlive').live('change', function(){\n  var assocNumDead = jQuery(this).closest('tr').find('.scNumDead');\n  assocNumDead.valid();\n});\n\$.validator.addMethod('no_record', function(value, element){\n  var numRows = jQuery('.scPresence').filter('[value=1]').length;\n  var isChecked = jQuery(element).filter('[checked]').length>0;\n  if(isChecked) return(numRows==0)\n  else  return(numRows>0);\n},\n  \"" . lang::get('validation_no_record') . "\");\n\$.validator.addMethod('scCheckTaxon', function(value, element){\n  var retVal = false;\n  var row = jQuery(element).closest('tr');\n  var classList = row.attr('class').split(/\\s+/);\n  \$.each( classList, function(index, item){\n    if (item.split(/-/)[0] === 'scMeaning') {\n      if(jQuery('.'+item).find(':checkbox').filter('[checked]').length>0) retVal=true;\n      if(jQuery('.'+item).find(':text').not('[value=]').length>0) retVal=true;\n    }});\n    // this is called at two points: when a value is entered and when the save button is called.\n  // If this fails then fine, there is no data entered for this species.\n  // If it passes then look up all the error paragraphs.\n  if(retVal){\n    \$.each( classList, function(index, item){\n      if (item.split(/-/)[0] === 'scMeaning') {\n        jQuery('.'+item).find('p.inline-error').each(function(index, item){\n          if(item.innerHTML == \"" . lang::get('validation_taxon_data') . "\")\n            jQuery(item).prev('.ui-state-error').removeClass('ui-state-error');\n            jQuery(item).remove();\n        });\n      }});\n  }\n  var inputs = row.find('input');\n  if(inputs.eq(inputs.length-1)[0] != element) return true; // nb jQuery 1.3, we are only interested in displaying the error for the last entry in the row.\n  return retVal;\n},\n  \"" . lang::get('validation_taxon_data') . "\");\njQuery('.scCheckTaxon:checkbox').live('change', function(value, element){\n  if(jQuery(this).filter('[checked]').length > 0){\n    var row = jQuery(this).closest('tr');\n    var classList = row.attr('class').split(/\\s+/);\n    \$.each( classList, function(index, item){\n      if (item.split(/-/)[0] === 'scMeaning') {\n        jQuery('.'+item).find('p.inline-error').each(function(index, item){\n          if(item.innerHTML == \"" . lang::get('validation_taxon_data') . "\")\n            jQuery(item).prev('.ui-state-error').removeClass('ui-state-error');\n            jQuery(item).remove();\n        });\n      }});\n  }\n});\n";
     return '';
 }
 protected static function get_control_lateJS($auth, $args, $tabalias, $options)
 {
     iform_mnhnl_addCancelButton($args['interface']);
     data_entry_helper::$javascript .= "\nhook_new_site_added = function(feature) {\n  if(!feature) return;\n  var name=createGridEntries(feature, true);\n  feature.attributes.cgRowNum=cgRowNum;\n  var centreGeom;\n  var centrefeature;\n  centreGeom = getCentroid(feature.geometry);\n  centrefeature = new OpenLayers.Feature.Vector(centreGeom);\n  centrefeature.attributes['new']=true;\n  centrefeature.attributes.highlighted=true;\n  centrefeature.attributes.SiteNum=feature.attributes.SiteNum;\n  centrefeature.attributes.cgRowNum=cgRowNum;\n  centrefeature.style = jQuery.extend({}, SiteListPrimaryLabelStyleHash);\n  centrefeature.style.label = name;\n  SiteLabelLayer.addFeatures([centrefeature]);\n  setNameDropDowns(false,name);\n  setGeomFields();\n};\n";
     iform_mnhnl_locationmodule_lateJS($auth, $args, $tabalias, $options);
     return '';
 }
Example #5
0
 /**
  * Insert any custom JS for this form: this may be related to attributes, which are included
  * as part of inherited generic code.
  * Does not include any HTML.
  */
 protected static function get_control_customJS($auth, $args, $tabalias, $options)
 {
     $r = '';
     $numRows = 2;
     $numCols = 1;
     $startPos = 2;
     iform_mnhnl_addCancelButton($args['interface']);
     $r .= self::getSiteTypeJS($auth, $args);
     data_entry_helper::$javascript .= "\nvar other = jQuery('[name=smpAttr\\:" . $args['entranceDefectiveCommentAttrID'] . "],[name^=smpAttr\\:" . $args['entranceDefectiveCommentAttrID'] . "\\:]');\nother.next().remove(); // remove break\nother.prev().remove(); // remove legend\nother.removeClass('wide').remove(); // remove Other field, then bolt in after the other radio button.\njQuery('[name^=smpAttr]').filter(':checkbox').filter('[value=" . $args['entranceDefectiveTermID'] . "],[value^=" . $args['entranceDefectiveTermID'] . "\\:]').parent().append(other);\n\nvar other = jQuery('[name=smpAttr\\:" . $args['disturbanceCommentAttrID'] . "],[name^=smpAttr\\:" . $args['disturbanceCommentAttrID'] . "\\:]');\nother.next().remove(); // remove break\nother.prev().remove(); // remove legend\nother.removeClass('wide').remove(); // remove Other field, then bolt in after the other radio button.\njQuery('[name^=smpAttr]').filter(':checkbox').filter('[value=" . $args['disturbanceOtherTermID'] . "],[value^=" . $args['disturbanceOtherTermID'] . "\\:]').parent().append(other);\n";
     if (self::$mode != self::MODE_EXISTING_RO) {
         if (lang::get('validation_required') != 'validation_required') {
             data_entry_helper::$late_javascript .= "\n    \t\$.validator.messages.required = \"" . lang::get('validation_required') . "\";";
         }
         if (lang::get('validation_max') != 'validation_max') {
             data_entry_helper::$late_javascript .= "\n    \t\$.validator.messages.max = \$.validator.format(\"" . lang::get('validation_max') . "\");";
         }
         if (lang::get('validation_min') != 'validation_min') {
             data_entry_helper::$late_javascript .= "\n    \t\$.validator.messages.min = \$.validator.format(\"" . lang::get('validation_min') . "\");";
         }
         if (lang::get('validation_number') != 'validation_number') {
             data_entry_helper::$late_javascript .= "\n    \t\$.validator.messages.number = \$.validator.format(\"" . lang::get('validation_number') . "\");";
         }
         if (lang::get('validation_digits') != 'validation_digits') {
             data_entry_helper::$late_javascript .= "\n    \t\$.validator.messages.digits = \$.validator.format(\"" . lang::get('validation_digits') . "\");";
         }
         if (lang::get('validation_integer') != 'validation_integer') {
             data_entry_helper::$late_javascript .= "\n    \t\$.validator.messages.integer = \$.validator.format(\"" . lang::get('validation_integer') . "\");";
         }
         data_entry_helper::$late_javascript .= "\n    \$.validator.addMethod('fillgroup', function(value, element){\n    var valid = jQuery(element).closest('tr').find(':text').not('[value=]').length > 0 ||\n    jQuery(element).closest('tr').find(':checkbox').filter('[checked]').length > 0;\n    // when this field is changed and becomes valid, remove the error codes on all the associated fields.\n    if(valid){\n    \$(element).removeClass('ui-state-error');\n    var to_valid = \$(element).closest('tr').find('.fillgroup').filter('.ui-state-error');\n    if(to_valid.length) to_valid.removeClass('ui-state-error').valid();\n    }\n    return valid;\n    },\n    \"" . lang::get('validation_fillgroup') . "\");";
         data_entry_helper::$javascript .= "\nif(\$.browser.msie && \$.browser.version < 9)\n  \$('input[type=radio],[type=checkbox]').live('click', function(){\n    this.blur();\n    this.focus();\n  });\ncheckCheckStatus = function(){\n  jQuery('[name^=smpAttr]').filter(':checkbox').filter('[value=" . $args['entranceDefectiveTermID'] . "],[value^=" . $args['entranceDefectiveTermID'] . "\\:]').each(function(){\n    if(this.checked) // note not setting the required flag.\n      jQuery('[name=smpAttr\\:" . $args['entranceDefectiveCommentAttrID'] . "],[name^=smpAttr\\:" . $args['entranceDefectiveCommentAttrID'] . "\\:]').removeAttr('readonly');\n    else\n      jQuery('[name=smpAttr\\:" . $args['entranceDefectiveCommentAttrID'] . "],[name^=smpAttr\\:" . $args['entranceDefectiveCommentAttrID'] . "\\:]').val('').attr('readonly',true);\n  });\n  jQuery('[name^=smpAttr]').filter(':checkbox').filter('[value=" . $args['disturbanceOtherTermID'] . "],[value^=" . $args['disturbanceOtherTermID'] . "\\:]').each(function(){\n    if(this.checked)\n      jQuery('[name=smpAttr\\:" . $args['disturbanceCommentAttrID'] . "],[name^=smpAttr\\:" . $args['disturbanceCommentAttrID'] . "\\:]').addClass('required').removeAttr('readonly');\n    else\n      jQuery('[name=smpAttr\\:" . $args['disturbanceCommentAttrID'] . "],[name^=smpAttr\\:" . $args['disturbanceCommentAttrID'] . "\\:]').removeClass('required').val('').attr('readonly',true);\n  });\n  };\njQuery('[name^=smpAttr]').filter(':checkbox').change(checkCheckStatus);\ncheckCheckStatus();\n";
     }
     if (isset($args['col_widths']) && $args['col_widths']) {
         $colWidths = explode(',', $args['col_widths']);
         for ($i = 0; $i < count($colWidths); $i++) {
             data_entry_helper::$javascript .= "\njQuery('.mnhnl-species-grid > thead').find('th').not(':hidden').filter(':eq(" . $i . ")').width('";
             if ($colWidths[$i] == '') {
                 data_entry_helper::$javascript .= "auto');";
             } else {
                 data_entry_helper::$javascript .= $colWidths[$i] . "%');";
             }
         }
     }
     // Move the Temperature and Humidity fields side by side.
     $removeBreakIDs = explode(':', $args['removeBreakIDs']);
     foreach ($removeBreakIDs as $removeBreakID) {
         data_entry_helper::$javascript .= "\njQuery('[name=smpAttr\\:" . $removeBreakID . "],[name^=smpAttr\\:" . $removeBreakID . "\\:]').css('margin-right', '20px').nextAll('br').eq(0).remove();";
     }
     if (!empty($args['attributeValidation']) && self::$mode != self::MODE_EXISTING_RO) {
         $rules = array();
         $argRules = explode(';', $args['attributeValidation']);
         foreach ($argRules as $rule) {
             $rules[] = explode(',', $rule);
         }
         foreach ($rules as $rule) {
             // But only do if a parameter given as rule:param - eg min:-40
             for ($i = 1; $i < count($rule); $i++) {
                 if (strpos($rule[$i], ':') !== false) {
                     $details = explode(':', $rule[$i]);
                     data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').attr('" . $details[0] . "'," . $details[1] . ");";
                 } else {
                     if ($rule[$i] == 'no_observation') {
                         data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').filter(':checkbox').rules('add', {no_observation: true});\nhook_species_checklist_delete_row=function() {\n  if(jQuery('.scPresence').filter(':checkbox').filter('[checked]').length==0)\n    jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').removeAttr('disabled');\n  else\n    jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').filter(':checkbox').attr('disabled','disabled').removeAttr('checked');\n};\nhook_species_checklist_pre_delete_row=function(e) {\n  if(!confirm(\"" . lang::get('Are you sure you want to delete this row?') . "\")) return false;\n  var row = \$(e.target.parentNode);\n  row.find('*').removeClass('ui-state-error');\n  row.find('.inline-error').remove();\n  return true;\n};\n// possible clash with link_species_popups, so latter disabled. First get the meaning id for the taxon, then all taxa with that meaning.\nhook_species_checklist_new_row.push(function(rowData) {\n  jQuery.getJSON('" . data_entry_helper::$base_url . "/index.php/services/data/taxa_taxon_list/' + rowData.id +\n            '?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "&callback=?', function(mdata) {\n    if(mdata instanceof Array && mdata.length>0){\n      jQuery.getJSON('" . data_entry_helper::$base_url . "/index.php/services/data/taxa_taxon_list' +\n            '?mode=json&view=detail&auth_token=" . $auth['read']['auth_token'] . "&nonce=" . $auth['read']["nonce"] . "&taxon_meaning_id='+mdata[0].taxon_meaning_id+'&callback=?', function(data) {\n        var taxaList = '';\n        var duplicate=false;\n        if(data instanceof Array && data.length>0){\n          for (var i=0;i<data.length;i++){\n            if(data[i].id != mdata[0].id){\n              if(data[i].preferred == 'f')\n                taxaList += (taxaList == '' ? '' : ', ')+data[i].taxon;\n              else\n                taxaList = '<em>'+data[i].taxon+'</em>'+(taxaList == '' ? '' : ', '+taxaList);\n              // look for a checked presence checkbox that starts with this taxon ID\n              if(jQuery('.scPresence').filter(':checkbox').filter('[checked]').filter('[name^=sc\\:'+data[i].id+'\\:]').length>0)\n                duplicate=true;\n            } else\n              if(jQuery('.scPresence').filter(':checkbox').filter('[checked]').filter('[name^=sc\\:'+data[i].id+'\\:]').length>1)\n                duplicate=true;\n          }\n          if(duplicate){\n            alert(\"" . lang::get('LANG_Duplicate_Taxon') . "\");\n            jQuery('.extraCommonNames').filter('[tID='+mdata[0].id+']').closest('tr').remove();\n          } else {\n            jQuery('.extraCommonNames').filter('[tID='+mdata[0].id+']').closest('tr').find('.scOccAttrCell').find('input').eq(0).addClass('fillgroup');\n            jQuery('.extraCommonNames').filter('[tID='+mdata[0].id+']').closest('tr').find('.scOccAttrCell').find('select').addClass('required').after('<span class=\"deh-required\">*</span>');\n            jQuery('.extraCommonNames').filter('[tID='+mdata[0].id+']').append(' - '+taxaList).removeClass('extraCommonNames');\n          }\n        }\n      });\n    }})\n    hook_species_checklist_delete_row();\n});\nhook_species_checklist_delete_row();\n\$.validator.addMethod('no_observation', function(arg1, arg2){\n  var numRows = jQuery('.scPresence').filter(':checkbox').filter('[checked]').length;\n  var isChecked = jQuery('[name='+jQuery(arg2).attr('name')+']').not(':hidden').filter('[checked]').length>0;\n  if(isChecked) return(numRows==0)\n  else if(numRows>0) return true;\n  // Not checked, no rows: ensure no obs can be filled in, and flag failure.\n  jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').removeAttr('disabled');\n  // this is being used against a boolean checkbox, which has a hidden zero field before. Have to tag on to later field explicitly.\n  return false;\n},\n  \"" . lang::get('validation_no_observation') . "\");\n  ";
                     } else {
                         if (substr($rule[0], 3, 4) != 'Attr') {
                             // have to add for non attribute case.
                             data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').addClass('" . $rule[$i] . "');";
                         }
                     }
                 }
             }
         }
     }
     if (array_key_exists('sample:id', data_entry_helper::$entity_to_load)) {
         data_entry_helper::$late_javascript .= "\nsetupButtons(\$('#controls'), 1);\nsetupButtons(\$('#controls'), 2);\nsetupButtons(\$('#controls'), 0);";
     }
     $smpAttributes = data_entry_helper::getAttributes(array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']));
     foreach ($smpAttributes as $attrId => $attr) {
         if (strcasecmp($attr['untranslatedCaption'], 'Bat visit') == 0) {
             data_entry_helper::$late_javascript .= "\njQuery('#smpAttr\\\\:{$attrId}').next().after(\"<span class='extra-text'>" . lang::get('LANG_Site_Extra') . "</span>\");";
         }
     }
     return $r;
 }
 protected static function get_control_customJS($auth, $args, $tabalias, $options)
 {
     global $indicia_templates;
     data_entry_helper::$javascript .= "\nif(\$.browser.msie && \$.browser.version < 9)\n  \$('input[type=radio],[type=checkbox]').live('click', function(){\n    this.blur();\n    this.focus();\n});\n";
     self::$check_or_radio_group_template = $indicia_templates['check_or_radio_group'];
     self::$check_or_radio_group_item_template = $indicia_templates['check_or_radio_group_item'];
     $indicia_templates['check_or_radio_group'] = '<div class="radio_group_container"><span {class}>{items}</span></div>';
     $indicia_templates['check_or_radio_group_item'] = '<nobr><div class="radio_group_item"><input type="{type}" name="{fieldname}" id="{itemId}" value="{value}"{class}{checked} {disabled}/><label for="{itemId}">{caption}</label></div></nobr> {sep}';
     if (isset($options['resizeRadioGroupSelector'])) {
         $selectors = explode(',', $options['resizeRadioGroupSelector']);
         foreach ($selectors as $selector) {
             data_entry_helper::$javascript .= "resize_radio_groups('" . $selector . "');\n";
         }
     }
     data_entry_helper::$javascript .= "\nindiciaData.resizeSpeciesRadioGroup = " . (isset($options['resizeRadioGroupSelector']) && (in_array('*', $selectors) || in_array('species', $selectors)) ? 'true' : 'false') . ";\n";
     if (lang::get('validation_required') != 'validation_required') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.required = \"" . lang::get('validation_required') . "\";";
     }
     if (lang::get('validation_max') != 'validation_max') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.max = \$.validator.format(\"" . lang::get('validation_max') . "\");";
     }
     if (lang::get('validation_min') != 'validation_min') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.min = \$.validator.format(\"" . lang::get('validation_min') . "\");";
     }
     if (lang::get('validation_number') != 'validation_number') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.number = \$.validator.format(\"" . lang::get('validation_number') . "\");";
     }
     if (lang::get('validation_digits') != 'validation_digits') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.digits = \$.validator.format(\"" . lang::get('validation_digits') . "\");";
     }
     if (lang::get('validation_integer') != 'validation_integer') {
         data_entry_helper::$late_javascript .= "\n\$.validator.messages.integer = \$.validator.format(\"" . lang::get('validation_integer') . "\");";
     }
     // possible clash with link_species_popups, so latter disabled.
     iform_mnhnl_addCancelButton($args['interface']);
     $attrOpts = array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']);
     if (isset($args['sample_method_id']) && $args['sample_method_id'] != "") {
         $attrOpts['sample_method_id'] = $args['sample_method_id'];
     }
     $attributes = data_entry_helper::getAttributes($attrOpts);
     foreach ($attributes as $attribute) {
         data_entry_helper::$javascript .= "\$('#smpAttr\\\\:" . $attribute['attributeId'] . "').addClass('smpAttr-" . str_replace(' ', '', ucWords($attribute['untranslatedCaption'])) . "');\n";
     }
     $restrictText = array();
     if (isset($options["attrRestrictions"]) && $options["attrRestrictions"] != "") {
         $restrictionRules = explode(';', $options["attrRestrictions"]);
         foreach ($restrictionRules as $restrictionRule) {
             $parts = explode(':', $restrictionRule);
             $valList = array();
             for ($i = 2; $i < count($parts); $i++) {
                 $values = explode(',', trim($parts[$i]));
                 $valString = "{value : " . $values[0] . ", list: [\"";
                 unset($values[0]);
                 $valList[] = $valString . implode("\",\"", $values) . "\"]}";
             }
             $restrictText[] = "{parent : " . $parts[0] . ", child : " . $parts[1] . ",\n  values: [" . implode(",\n    ", $valList) . "]}";
         }
     }
     data_entry_helper::$javascript .= "\nrelationships = [" . implode(",\n", $restrictText) . "\n];";
     if (isset($options["attrRestrictionsProcessOrder"]) && $options["attrRestrictionsProcessOrder"] != "") {
         $attrOrder = explode(':', $options["attrRestrictionsProcessOrder"]);
         if (!isset($options["attrRestrictionsDuplicateAttrList"])) {
             $options["attrRestrictionsDuplicateAttrList"] = $options["attrRestrictionsProcessOrder"];
         }
         $duplicateAttrList = explode(':', $options["attrRestrictionsDuplicateAttrList"]);
         data_entry_helper::$javascript .= "\nattrRestrictionsProcessOrder = [" . implode(',', $attrOrder) . "];\nattrRestrictionsDuplicates = " . (isset($options["attrRestrictionsEnforceDuplicates"]) ? 'true' : 'false') . ";\nattrRestrictionsDuplicateAttrList = [" . implode(',', $duplicateAttrList) . "];\n// set up pre-existing ones: trigger first which will bubble through\njQuery('.mnhnl-species-grid').find('[name\$=occAttr\\:" . $attrOrder[0] . "],[name*=occAttr\\:" . $attrOrder[0] . "\\:]').each(function(){\n    set_up_relationships(" . $attrOrder[1] . ", \$(this), false, " . (isset($options["attrRestrictionsEnforceDuplicates"]) ? 'true' : 'false') . ");\n});\n// Set up what happens when existing fields are changed\n";
         // need to check all but last
         for ($i = 0; $i < count($attrOrder) - 1; $i++) {
             data_entry_helper::$javascript .= "\njQuery('.mnhnl-species-grid').find('[name\$=occAttr\\:" . $attrOrder[$i] . "],[name*=occAttr\\:" . $attrOrder[$i] . "\\:]').change(function(){\n  set_up_relationships(" . $attrOrder[$i + 1] . ", \$(this), true, " . (isset($options["attrRestrictionsEnforceDuplicates"]) ? 'true' : 'false') . ");\n});\n";
         }
         data_entry_helper::$javascript .= "// last is special - only updates similar on other rows.\njQuery('.mnhnl-species-grid').find('[name\$=occAttr\\:" . $attrOrder[count($attrOrder) - 1] . "],[name*=occAttr\\:" . $attrOrder[count($attrOrder) - 1] . "\\:]').change(function(){\n  set_up_last_relationship(this, " . $attrOrder[count($attrOrder) - 1] . ", " . $attrOrder[count($attrOrder) - 2] . ", true);\n});\n";
         // for duplicate checks had to trigger on all duplicate based fields. Don't include the precision field, which is on the sample field.
         $selector = isset($options['includeSubSample']) ? '.imp-srefX,.imp-srefY' : '';
         foreach ($duplicateAttrList as $attr) {
             if (!in_array($attr, $attrOrder)) {
                 $selector .= ($selector == "" ? "" : ",") . "[name\$=occAttr\\:" . $attr . "],[name*=occAttr\\:" . $attr . "\\:]";
             }
         }
         if ($selector != "" && isset($options["attrRestrictionsEnforceDuplicates"])) {
             data_entry_helper::$javascript .= "\nattrRestrictionsDuplicateSelector = \"" . $selector . "\";\njQuery('.mnhnl-species-grid').find('" . $selector . "').change(function(){\n  set_up_last_relationship(this, " . $attrOrder[count($attrOrder) - 1] . ", " . $attrOrder[count($attrOrder) - 2] . ", true);\n});\n";
         }
     }
     if (!empty($args['attributeValidation'])) {
         $rules = array();
         $argRules = explode(';', $args['attributeValidation']);
         foreach ($argRules as $rule) {
             $rules[] = explode(',', $rule);
         }
         foreach ($rules as $rule) {
             // But only do if a parameter given as rule:param - eg min:-40
             for ($i = 1; $i < count($rule); $i++) {
                 if (strpos($rule[$i], ':') !== false) {
                     $details = explode(':', $rule[$i]);
                     data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').attr('" . $details[0] . "'," . $details[1] . ");";
                 } else {
                     if ($rule[$i] == 'no_observation') {
                         data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').filter(':checkbox').rules('add', {no_observation: true});\nhook_species_grid_changed=function() {\n  if(jQuery('.scPresence').filter('[value=true]').length==0)\n    jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').removeAttr('disabled');\n  else\n    jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').filter(':checkbox').attr('disabled','disabled').removeAttr('checked');\n};\nhook_species_grid_changed();\n\$.validator.addMethod('no_observation', function(arg1, arg2){\n  var numRows = jQuery('.scPresence').filter('[value=true]').length;\n  var isChecked = jQuery('[name='+jQuery(arg2).attr('name')+']').not(':hidden').filter('[checked]').length>0;\n  if(isChecked) return(numRows==0)\n  else if(numRows>0) return true;\n  // Not checked, no rows: ensure no obs can be filled in, and flag failure.\n  jQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').removeAttr('disabled');\n  // this is being used against a boolean checkbox, which has a hidden zero field before. Have to tag on to later field explicitly.\n  return false;\n},\n  \"" . lang::get('validation_no_observation') . "\");\n";
                     } else {
                         if ($rule[$i] == 'end_time') {
                             // we are assuming this is on the main supersample.
                             $attrOpts = array('valuetable' => 'sample_attribute_value', 'attrtable' => 'sample_attribute', 'key' => 'sample_id', 'fieldprefix' => 'smpAttr', 'extraParams' => $auth['read'], 'survey_id' => $args['survey_id']);
                             if (isset($args['sample_method_id']) && $args['sample_method_id'] != "") {
                                 $attrOpts['sample_method_id'] = $args['sample_method_id'];
                             }
                             $sampleAttrs = data_entry_helper::getAttributes($attrOpts, true);
                             // fetch start time.
                             $found = false;
                             foreach ($sampleAttrs as $id => $attr) {
                                 if ($attr["untranslatedCaption"] == "Start time") {
                                     $found = $id;
                                     break;
                                 }
                             }
                             if ($found === false) {
                                 continue;
                             }
                             data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').rules('add', {end_time: true});\n\$.validator.addMethod('end_time', function(value, element){\n  var startTime = jQuery('[name=smpAttr\\:" . $found . "],[name^=smpAttr\\:" . $found . "\\:]') \n  if(value=='' || startTime.val() == '') return true; \n  return (value >= startTime.val()); \n},\n  \"" . lang::get('validation_end_time') . "\");\n";
                         } else {
                             if ($rule[$i] == 'N=2') {
                                 // We change the way this is handled: no longer a validation rule as this is only applied when the next  step is pressed
                                 // we want immediate, restrict number checkable. Still are assuming this is on the main supersample.
                                 // allow a maximum of 2 entries in a multiple value checkbox set.
                                 $func = "check_N2_" . str_replace(':', '_', $rule[0]);
                                 $selector = str_replace(':', '\\:', $rule[0]);
                                 data_entry_helper::$late_javascript .= $func . " = function(){\n  var controls = jQuery('[name=" . $selector . "\\[\\]],[name=" . $selector . "],[name^=" . $selector . "\\:]').filter('[type=checkbox]'); \n  var checkedControls = controls.filter(':checked'); \n  if(checkedControls.length >= 2)\n    controls.not(':checked').attr('disabled',true);\n  else\n    controls.removeAttr('disabled');\n};\njQuery('[name=" . $selector . "\\[\\]],[name=" . $selector . "],[name^=" . $selector . "\\:]').click(" . $func . ");\n" . $func . "();\n";
                             } else {
                                 if ($rule[$i] == 'N=3') {
                                     // we want immediate, restrict number checkable..
                                     // allow a maximum of 3 entries in a multiple value checkbox set. name will be the same.
                                     $func = "check_N3_" . str_replace(':', '_', $rule[0]);
                                     $selector = str_replace(':', '\\:', $rule[0]);
                                     data_entry_helper::$late_javascript .= $func . "_sub = function(elem){\n  var controls = jQuery('[name='+elem.name+']'); \n  var checkedControls = controls.filter(':checked');\n  if(checkedControls.length >= 3)\n    controls.not(':checked').attr('disabled',true);\n  else\n    controls.removeAttr('disabled');\n};\n" . $func . " = function(){\n  " . $func . "_sub(this);\n};\njQuery('[name\$=" . $selector . "\\[\\]]').live('click', " . $func . ");\njQuery('[name\$=" . $selector . "\\[\\]]').each(function(){\n  " . $func . "_sub(this);\n});\n";
                                 } else {
                                     if (substr($rule[0], 3, 4) != 'Attr') {
                                         // have to add for non attribute case.
                                         data_entry_helper::$late_javascript .= "\njQuery('[name=" . str_replace(':', '\\:', $rule[0]) . "],[name^=" . str_replace(':', '\\:', $rule[0]) . "\\:]').addClass('" . $rule[$i] . "');";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!isset($options['speciesListInTextAttr'])) {
         return '';
     }
     $ctrlArgs = explode(',', $options['speciesListInTextAttr']);
     data_entry_helper::$javascript .= "\nindiciaData.speciesListInTextSelector = '." . $ctrlArgs[0] . "';\nindiciaData.None = '" . lang::get('None') . "';\nindiciaData.speciesListInTextLabel = '" . lang::get('Add supporting plant species to list') . "';\nindiciaData.speciesListInTextSpeciesList = " . $ctrlArgs[1] . ";\nindiciaData.speciesListInTextMax = '" . $ctrlArgs[2] . "';\n";
     return '';
 }