Commit 9ba6e2b2 authored by John Punzalan's avatar John Punzalan

Update entity add industry select

parent 20b02be8
......@@ -316,6 +316,17 @@ class Esi_Management_Admin {
}
public function esi_industries_ajax_callback(){
$data = $_POST;
if(!empty($data))
{
$response = array('industry' => esi_get_list_industry($data['radar_id']));
echo json_encode($response);
wp_die();
}
}
/**
* Show custom user profile fields
* @param obj $user The user object.
......
......@@ -32,6 +32,7 @@
$('#radar_industry').multiSelect();
$('#radar_function').multiSelect();
$('#industry_sub_id').multiSelect();
$("#radar_id").live('change', function(el){
$.ajax({
url: ajaxurl,
......@@ -72,6 +73,7 @@
$('#radar_industry').multiSelect();
$('#radar_function').multiSelect();
$('#industry_sub_id').multiSelect();
if($(".chosen-select")){
$(".chosen-select").chosen({disable_search_threshold: 10, width: "350px"});
......@@ -220,4 +222,30 @@
$("select#esi_function_table").treeMultiselect({startCollapsed: false});
});
$("#industry_id").live('change', function(el){
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
'action': 'esi_industries_ajax_action',
'radar_id': $(this).val()
},
success:function(response) {
var data = JSON.parse(response);
$("#industry_sub_id").find("option:gt(0)").remove();
$.each(data.industry, function(i, d){
$('#industry_sub_id').multiSelect('addOption', { value: d.id, text: d.name, index: i });
});
},
error: function(errorThrown){
console.log(errorThrown);
}
});
});
$('#industry_sub_id').multiSelect();
})( jQuery );
......@@ -172,4 +172,21 @@ function sample_admin_notice_success() {
<p><?php _e( 'Done!', 'sample-text-domain' ); ?></p>
</div>
<?php
}
/**
* Fetch industry array
*
* @param int $id
*
* @return array
*/
function esi_get_list_industry( $id = 0 ) {
global $wpdb;
// Get Selected industry mapping
$arrSelectedIndustry = $wpdb->get_results("SELECT * FROM " .$wpdb->prefix . "esi_industry WHERE parent = " . $id . " ORDER BY name ASC");
return $arrSelectedIndustry;
}
\ No newline at end of file
......@@ -16,6 +16,8 @@ global $wpdb;
$item = esi_get_entity( $id );
$countries = esi_get_all_countries();
$entity_types = esi_get_all_entity_type_id();
$industries = array();
$industries = array_merge(esi_get_list_industry(), $industries);
add_thickbox();
?>
......@@ -151,6 +153,28 @@ add_thickbox();
<input type="text" name="latest-round-type" id="latest-round-type" class="regular-text" placeholder="<?php echo esc_attr( 'Latest Round Type', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( $item->latest_round_type ):''; ?>" />
</td>
</tr>
<hr />
<tr class="row-entity-industry">
<th scope="row">
<label for="industry_id"><?php _e( 'Industry', 'esi' ); ?></label>
</th>
<td>
<select id="industry_id" name="industry_id[]">
<option value="0">Select an industry</option>
<?php foreach ($industries as $industry) : ?>
<option value="<?= $industry->id ?>"><?= $industry->name ?></option>
<?php endforeach; ?>
</select><br />
</td>
</tr>
<tr class="row-entity-sub-industry">
<th scope="row">
</th>
<td>
<select id="industry_sub_id" name="industry_sub_id[]" multiple="multiple">
</select><br />
</td>
</tr>
</tbody>
</table>
......
......@@ -216,6 +216,7 @@ class Esi_Management {
$this->loader->add_action( 'wp_ajax_esi_media_ajax_action', $plugin_admin, 'esi_media_ajax_callback' );
$this->loader->add_action( 'wp_ajax_esi_investment_ajax_action', $plugin_admin, 'esi_investment_ajax_callback' );
$this->loader->add_action( 'wp_ajax_esi_radar_ajax_action', $plugin_admin, 'esi_radar_ajax_callback' );
$this->loader->add_action( 'wp_ajax_esi_industries_ajax_action', $plugin_admin, 'esi_industries_ajax_callback' );
// Add radars field to user form
// $this->loader->add_action('show_user_profile', $plugin_admin, 'esi_custom_user_profile_fields');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment