protected static function get_control_species($auth, $args, $tabAlias, $options) { data_entry_helper::$onload_javascript .= "indiciaFns.bindTabsActivate(\$(\$('#{$tabAlias}').parent()), function(event, ui) {\r\n panel = typeof ui.newPanel==='undefined' ? ui.panel : ui.newPanel[0];\r\n if (panel.id==='{$tabAlias}') { setSectionDropDown(); }\r\n });\n"; // we need a place to store the subsites, to save loading from the db on submission $r = '<input type="hidden" name="subsites" id="subsites" value="" />'; // plus hiddens to store the main sample's sref info $r .= data_entry_helper::hidden_text(array('fieldname' => 'sample:entered_sref', 'id' => 'imp-sref')); $r .= data_entry_helper::hidden_text(array('fieldname' => 'sample:entered_sref_system', 'id' => 'imp-sref-system')); $r .= data_entry_helper::hidden_text(array('fieldname' => 'sample:geom', 'id' => 'imp-geom')); // plus the sample method ids $sampleMethods = helper_base::get_termlist_terms($auth, 'indicia:sample_methods', array('Transect', 'Transect Section')); $r .= '<input type="hidden" name="sample:sample_method_id" value="' . $sampleMethods[0]['id'] . '" />'; $r .= '<input type="hidden" name="subsample:sample_method_id" value="' . $sampleMethods[1]['id'] . '" />'; // This option forces the grid to load all child sample occurrences, though we will ignore the hidden SampleIDX column and instead // use the section column to bind to samples $options['speciesControlToUseSubSamples'] = true; $r .= parent::get_control_species($auth, $args, $tabAlias, $options); // build an array of existing sub sample IDs, keyed by subsite location Id. $subSampleIds = array(); if (isset(data_entry_helper::$entity_to_load)) { foreach (data_entry_helper::$entity_to_load as $key => $value) { if (preg_match('/^sc:(\\d+):(\\d+):sample:id$/', $key, $matches)) { $subSampleIds[data_entry_helper::$entity_to_load["sc:{$matches['1']}:{$matches['2']}:sample:location_id"]] = $value; } } } $r .= '<input type="hidden" name="subSampleIds" value="' . htmlspecialchars(json_encode($subSampleIds)) . '" />'; return $r; }
/** * Returns the species checklist input control. * @param array $auth Read authorisation tokens * @param array $args Form configuration * @param array $options additional options for the control, e.g. those configured in the form structure. * @return HTML for the species_checklist control. */ protected static function get_control_species($auth, $args, $tabAlias, $options) { $options['subSamplePerRow'] = true; $options['speciesControlToUseSubSamples'] = true; $r = parent::get_control_species($auth, $args, $tabAlias, $options); return $r; }
/** * A variant of the species grid control with just the flexible search species available. */ protected static function get_control_searchspecies($auth, $args, $tabAlias, $options) { // build a list of the search species IDs $ttlIds = array(); foreach (self::$parentSampleAttrs['smpAttr:' . $args['search_species_transect_attr_id']]['default'] as $value) { $ttlIds[] = $value['default']; } if (empty($ttlIds)) { return '<p>' . lang::get('Please fill in the search species on the front page.') . '</p>'; } // safety $args['list_id'] = $args['extra_list_id']; $args['taxon_filter_field'] = 'taxa_taxon_list_id'; $args['taxon_filter'] = implode("\n", $ttlIds); $options['rowInclusionCheck'] = 'alwaysFixed'; $options['id'] = 'search-list'; unset($args['extra_list_id']); return parent::get_control_species($auth, $args, $tabAlias, $options); }
/** * Returns the species checklist input control setup so that there is one subsample for each tree on the grid. * @param array $auth Read authorisation tokens * @param array $args Form configuration * @param array $options additional options for the control, e.g. those configured in the form structure. * @return HTML for the species_checklist control. */ protected static function get_control_species($auth, $args, $tabAlias, $options) { $options['subSamplePerRow'] = true; $options['speciesControlToUseSubSamples'] = true; //When the user enters trees onto the species, then we automatically plot them onto the map. //The is done on load (in edit mode) and onChange data_entry_helper::$javascript .= "\n mapInitialisationHooks.push(function (div) {\n var i, featureToRemove;\n var defaultStyle = new OpenLayers.Style({\n 'pointRadius': 30,\n 'graphicWidth': 16,\n 'graphicHeight': 16,\n 'graphicOpacity': 0.8,\n 'fillOpacity': 0,\n 'strokeColor': 'green',\n 'strokeOpacity': 1,\n 'strokeWidth': 2,\n });\n var s = new OpenLayers.StyleMap({\n 'default': defaultStyle, \n });\n //Array to store tree feature id associated with each tree grid ref cell, if this cell changes then we\n //can change the feature as required\n var treeFeaturesStore=[];\n indiciaData.mapdiv = div;\n treeLayer = new OpenLayers.Layer.Vector('Tree Layer', {styleMap: s});\n indiciaData.mapdiv.map.addLayer(treeLayer); \n //Load tree features in edit mode\n \$(document).ready(function () {\n \$('[class^=\"scGridRef\"]').each(function () {\n if (\$(this).val()) {\n draw_tree_to_map(\$(this).val(), \$(this).attr('id'), treeFeaturesStore);\n }\n });\n });\n \n \$('[class^=\"scGridRef\"]').live('change',function () {\n //Remove old tree when change is made.\n //Cycle through the array of existing plotted trees, remove it if we find a match (match using id of the onscreen spatial referene text field)\n for (i=0; i<treeFeaturesStore.length; i++) {\n if (treeFeaturesStore[i][0]==\$(this).attr('id')) {\n featureToRemove = treeLayer.getFeatureById(treeFeaturesStore[i][1]);\n treeLayer.removeFeatures(featureToRemove);\n }\n }\n if (\$(this).val()) {\n draw_tree_to_map(\$(this).val(), \$(this).attr('id'), treeFeaturesStore);\n }\n });\n });"; //bng = British Nation Grid - Trees only support this spatial reference system data_entry_helper::$javascript .= "\n function draw_tree_to_map(bng_ref, fieldId, treeFeaturesStore) {\n var refString = \"'\" + bng_ref + \"'\";\n \$.getJSON(\"" . data_entry_helper::$base_url . "/index.php/services/spatial/sref_to_wkt\"+\n \"?sref=\" + bng_ref +\n \"&system=\" + \"OSGB\" +\n \"&callback=?\", \n function(data) {\n //Ignore errors as our regex spatial reference checker already handles this and we don't want to warn user twice\n if(typeof data.error == 'undefined') {\n var attributes = {name: 'tree_map'};\n var polygon=OpenLayers.Geometry.fromWKT(data.wkt);\n if (indiciaData.mapdiv.map.projection.getCode() != indiciaData.mapdiv.indiciaProjection.getCode()) {\n polygon.transform(indiciaData.mapdiv.indiciaProjection, indiciaData.mapdiv.map.projection);\n }\n var feature = new OpenLayers.Feature.Vector(polygon, attributes);\n treeLayer.addFeatures([feature]);\n //Store the feature against the tree field id, so we can remove it when the value is changed\n treeFeaturesStore.push([fieldId, feature.id]);\n }\n }\n );\n }"; $r = parent::get_control_species($auth, $args, $tabAlias, $options); return $r; }