Commit c018e35d authored by John Punzalan's avatar John Punzalan

Update Ajax calls for request JOIN News & Entity

parent aca9f395
...@@ -320,7 +320,18 @@ class Esi_Management_Admin { ...@@ -320,7 +320,18 @@ class Esi_Management_Admin {
$data = $_POST; $data = $_POST;
if(!empty($data)) if(!empty($data))
{ {
$response = array('industry' => esi_get_list_industry($data['radar_id'])); $response = array('industry' => esi_get_list_industry($data['industry_id']));
echo json_encode($response);
wp_die();
}
}
public function esi_technologies_ajax_callback(){
$data = $_POST;
if(!empty($data))
{
$response = array('returned_data' => esi_get_list_technology($data['id']));
echo json_encode($response); echo json_encode($response);
wp_die(); wp_die();
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
$('#radar_industry').multiSelect(); $('#radar_industry').multiSelect();
$('#radar_function').multiSelect(); $('#radar_function').multiSelect();
$('#industry_sub_id').multiSelect(); $('#industry_sub_id').multiSelect();
$('.join_sub_data_select').multiSelect();
$("#radar_id").live('change', function(el){ $("#radar_id").live('change', function(el){
$.ajax({ $.ajax({
url: ajaxurl, url: ajaxurl,
...@@ -230,7 +232,7 @@ ...@@ -230,7 +232,7 @@
type: 'POST', type: 'POST',
data: { data: {
'action': 'esi_industries_ajax_action', 'action': 'esi_industries_ajax_action',
'radar_id': $(this).val() 'industry_id': $(this).val()
}, },
success:function(response) { success:function(response) {
var data = JSON.parse(response); var data = JSON.parse(response);
...@@ -245,6 +247,32 @@ ...@@ -245,6 +247,32 @@
} }
}); });
}); });
$(".join_data_select").live('change', function(el){
var populate = $(this).data('populate');
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
'action': $(this).data('action'),
'id': $(this).val()
},
success:function(response) {
var data = JSON.parse(response);
$(populate).find("option:gt(0)").remove();
$.each(data.returned_data, function(i, d){
$(populate).multiSelect('addOption', { value: d.id, text: d.name, index: i });
});
},
error: function(errorThrown){
console.log(errorThrown);
}
});
});
$('#industry_sub_id').multiSelect(); $('#industry_sub_id').multiSelect();
......
...@@ -290,3 +290,19 @@ function esi_delete_news( $id = 0 ) { ...@@ -290,3 +290,19 @@ function esi_delete_news( $id = 0 ) {
global $wpdb; global $wpdb;
$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'esi_news WHERE id = %d', $id ) ); $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'esi_news WHERE id = %d', $id ) );
} }
/**
* Fetch technologies array
*
* @param int $id
*
* @return array
*/
function esi_get_list_technology( $id = 0 ) {
global $wpdb;
// Get Selected technology mapping
$arrSelectedTechnology = $wpdb->get_results("SELECT * FROM " .$wpdb->prefix . "esi_technology WHERE parent = " . $id . " ORDER BY name ASC");
return $arrSelectedTechnology;
}
...@@ -54,6 +54,8 @@ if ($radars_news) { ...@@ -54,6 +54,8 @@ if ($radars_news) {
$industry_news[] = esi_get_industry_by_news($id); $industry_news[] = esi_get_industry_by_news($id);
$function_news[] = esi_get_function_by_news($id); $function_news[] = esi_get_function_by_news($id);
$technologies = esi_get_list_technology();
add_thickbox(); add_thickbox();
?> ?>
...@@ -141,8 +143,8 @@ add_thickbox(); ...@@ -141,8 +143,8 @@ add_thickbox();
<option value="<?= $entity->id ?>" <?= ($item->entity_id == $entity->id)?'selected="selected"':'' ?>><?= $entity->name ?></option> <option value="<?= $entity->id ?>" <?= ($item->entity_id == $entity->id)?'selected="selected"':'' ?>><?= $entity->name ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<a href="#TB_inline?width=600&height=450&inlineId=esi-add-entity" <a href="/wp-admin/admin.php?page=esi-management-entity&action=new" target="_blank"
class="page-title-action thickbox" id="esi_add_entity" style="float:left;margin-top:5px;" onclick="self.parent.tb_remove();"> class="page-title-action" style="float:left;margin-top:5px;" >
Add entity Add entity
</a> </a>
</td> </td>
...@@ -183,11 +185,33 @@ add_thickbox(); ...@@ -183,11 +185,33 @@ add_thickbox();
Edit investment Edit investment
</a> </a>
<?php endif; ?> <?php endif; ?>
</p> </p>
</td> </td>
</tr> </tr>
<tr class="row-type-id"> <tr class="row-technology-id">
<th scope="row">
<label for="technology_id"><?php _e( 'Technology', 'esi' ); ?></label>
</th>
<td>
<select id="technology_id" name="technology_id" class="join_data_select" data-tablename="technology" data-action="esi_technologies_ajax_action" data-populate=".join_sub_data_select">
<option value="0">Select a Technology</option>
<?php foreach ($technologies as $technology) : ?>
<option value="<?= $technology->id ?>"><?= $technology->name ?></option>
<?php endforeach; ?>
</select><br />
</td>
</tr>
<tr class="row-entity-sub-industry">
<th scope="row">
Select Sub Technology <br/> (If needed)
</th>
<td>
<select id="technology_sub_id" name="technology_sub_id[]" class="join_sub_data_select" multiple="multiple">
</select><br />
</td>
</tr>
<tr class="row-type-id">
<th scope="row"> <th scope="row">
<label for="type_id"><?php _e( 'Type', 'esi' ); ?></label> <label for="type_id"><?php _e( 'Type', 'esi' ); ?></label>
</th> </th>
...@@ -199,8 +223,8 @@ add_thickbox(); ...@@ -199,8 +223,8 @@ add_thickbox();
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</td> </td>
</tr> </tr>
<tr class="row-type-id"> <tr class="row-type-id">
<th scope="row"> <th scope="row">
<label for="region_id"><?php _e( 'Region', 'esi' ); ?></label> <label for="region_id"><?php _e( 'Region', 'esi' ); ?></label>
</th> </th>
...@@ -212,17 +236,17 @@ add_thickbox(); ...@@ -212,17 +236,17 @@ add_thickbox();
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</td> </td>
</tr> </tr>
<tr class="row-publish-date"> <tr class="row-publish-date">
<th scope="row"> <th scope="row">
<label for="publish_date"><?php _e( 'Publish Date', 'esi' ); ?></label> <label for="publish_date"><?php _e( 'Publish Date', 'esi' ); ?></label>
</th> </th>
<td> <td>
<input type="date" name="publish_date" id="publish_date" class="regular-text" placeholder="<?php echo esc_attr( '', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( explode(' ', $item->publish_date)[0] ):''; ?>" required="required" /> <input type="date" name="publish_date" id="publish_date" class="regular-text" placeholder="<?php echo esc_attr( '', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( explode(' ', $item->publish_date)[0] ):''; ?>" required="required" />
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<input type="hidden" name="field_id" value="<?php echo ($item)?$item->id:0; ?>"> <input type="hidden" name="field_id" value="<?php echo ($item)?$item->id:0; ?>">
<input type="hidden" name="post_id" value="<?php echo ($item)?$item->post_id:''; ?>"> <input type="hidden" name="post_id" value="<?php echo ($item)?$item->post_id:''; ?>">
......
...@@ -217,6 +217,7 @@ class Esi_Management { ...@@ -217,6 +217,7 @@ class Esi_Management {
$this->loader->add_action( 'wp_ajax_esi_investment_ajax_action', $plugin_admin, 'esi_investment_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_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' ); $this->loader->add_action( 'wp_ajax_esi_industries_ajax_action', $plugin_admin, 'esi_industries_ajax_callback' );
$this->loader->add_action( 'wp_ajax_esi_technologies_ajax_action', $plugin_admin, 'esi_technologies_ajax_callback' );
// Add radars field to user form // Add radars field to user form
// $this->loader->add_action('show_user_profile', $plugin_admin, 'esi_custom_user_profile_fields'); // $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