<script>
$(document).ready( function() {
let accountId=$('#accountId').val();
$.get("http://devtest.simplevoip.us/ajax_functions.php?fn=get_account_devices&accountId="+accountId)
.done((data) => {
$.each(data, (i, elem) => {
$('#michelle').append(`<tr><td>${elem.deviceId}</td><td>${elem.name}</td><td><button data-device-id='${elem.deviceId}' class='detail'>More Detail</button></td></tr><tr><td colspan="2"><span style="font-size:9pt; font-style:italic;">product detail</span></td></tr>`)
})
})
.fail((error) => console.log(error))
.always(() => console.log('Done'));
});
</script>
ASKER
ASKER
$('#michelle').on('click', 'button', function(e) {
${'#someFormId').val( $(this).data('some-attribute') )
...
$('#myModal'),modal('show');
})
The above assumes you've attached the data attribute to each button. If it's somewhere else in your row, then you'll need to travers the DOM a little. You could potentially make it a little easier by setting one data atrribute and json encoding the entire dataset. You're then only having to retieve one attribute, decode it and you'll have all your data values. ASKER
<?php require_once("header.php");?>
<body>
<div class="container" style="height:100%;"><br>
<div class="shopping_bag">
<div class="content">
<div class="row">
<div class="col-xs-12">
<img src="images/header.jpg" class="img-responsive" style="border-radius:14px 14px 0px 0px; border:1px solid #fff;">
</div>
</div>
<div class="orange_row"><br>
<div class="white_background">
<table id="michelle" class="table">
<tr>
<td style="font-weight:bold; background-color:#000; color:#fff; text-align:center; border-right:1px solid #fff;">device id</td>
<td style="font-weight:bold; background-color:#000; color:#fff; text-align:center; border-right:1px solid #fff;">name</td>
<td style="font-weight:bold; background-color:#000; color:#fff; text-align:center;">edit</td>
</tr>
</table>
</div><br>
</div>
</div>
<div style="margin:auto; text-align:center; font-size:9pt; font-weight:bold; color:#ffffff;">
<br>Bruce Gust | (e) <a href="mailto:bruce@brucegust.com" style="color:#fff; text-decoration:none;">bruce@brucegust.com</a> (p) 615.618.2059
</div>
</div>
</div>
<input type="hidden" id="accountId" value="4b2e5ea8ca6231f67e1697768e5">
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</body>
<script>
$(document).ready( function() {
let accountId=$('#accountId').val();
$.get("http://devtest.simplevoip.us/ajax_functions.php?fn=get_account_devices&accountId="+accountId)
.done((data) => {
$.each(data, (i, elem) => {
$('#michelle').append(`<tr><td>${elem.deviceId}</td><td>${elem.name}</td><td><button data-device-id='${elem.deviceId}' class="detail">More Detail</button></td></tr>`)
})
})
.fail((error) => console.log(error))
.always(() => console.log('Done'));
$('#michelle').on('click', 'button', function(e) {
let deviceId = $(this).data('device-id');
console.log(deviceId);
});
});
</script>
</html>
I'm done for today, but I'll be up bright and early tomorrow morning.{"result":"SUCCESS","mac":"0D8E1CF76146","customerTemplateID":146,"codec":"DEFAULT","transport":"UDP","proxy":"AUTO","line2":"","line3":"","line4":"","lastAccess":"Config last pulled: 2019-11-26 20:27:05 CST","configID":12,"ip":"","gw":"","subnet":"","algo_output":null,"syslog":0}
$.each(data, (i, elem) => {
let row = $(`<tr><td>${elem.deviceId}</td><td>${elem.name}</td><td><button>More Detail</button></td></tr>`)
$('button', row).data('info', elem)
$('#michelle').append(row)
})
You'll see here that we create an object, set the data attribute on the button to elem (your object) and then append it to the #michelle div. This means that the entire object is now stored on the button as a data attribute called info.<div class="modal-body">
<form id="editForm">
<label>Account Id
<input type="text" name="accountid">
<label>MAC</label>
<input type="text" name="mac">
...
</form>
</div>
Notice how the form fields match the parameters that you update endpoint will take - that's because ultimately, we're just going to post that form to the endpoint to do the update. $('#michelle').on('click', 'button', function(e) {
let info = $(this).data('info') // retrieve the data from the button
$('input[name=mac]').val( info.mac ) // set the values of your form fields
...
$('#exampleModal).modal('show') // show the Modal form (you will need to add the ID to your Modal HTML)
});
All we're doing here is retrieving the info object from the button and setting the form fields to the values we stored. Once done, we just show the Modal popup.$('#saveChanges').click(function(e) {
let myForm = $('#editForm')
$.ajax({
url : 'http://devtest.simplevoip.us/ajax_functions.php?fn=update_config',
method : 'post',
data : myForm.serialize(),
})
.done({resp) => {
// your update has been done.
$('#exampleModal').modal('hide')
})
})
I think that's the basic moving parts covered, but you'll need to check the code over and edit it to your needs. It'll be easier to handle all of this if you break it down into individual steps:ASKER
ASKER
ASKER
<?php require_once("header.php");?>
<body>
<div class="container" style="height:100%;"><br>
<div class="shopping_bag">
<div class="content">
<div class="row">
<div class="col-xs-12">
<img src="images/header.jpg" class="img-responsive" style="border-radius:14px 14px 0px 0px; border:1px solid #fff;">
</div>
</div>
<div class="orange_row"><br>
<div class="white_background">
<table id="michelle" class="table">
<tr>
<td style="font-weight:bold; background-color:#000; color:#fff; text-align:center; border-right:1px solid #fff;">device id</td>
<td style="font-weight:bold; background-color:#000; color:#fff; text-align:center; border-right:1px solid #fff;">name</td>
<td style="font-weight:bold; background-color:#000; color:#fff; text-align:center;">edit</td>
</tr>
</table>
</div><br>
</div>
</div>
<div style="margin:auto; text-align:center; font-size:9pt; font-weight:bold; color:#ffffff;">
<br>Bruce Gust | (e) <a href="mailto:bruce@brucegust.com" style="color:#fff; text-decoration:none;">bruce@brucegust.com</a> (p) 615.618.2059
</div>
</div>
</div>
<input type="hidden" id="accountId" value="4b2e5ea8ca6231f67e1697768e5">
</body>
<script>
$(document).ready( function() {
let accountId=$('#accountId').val();
$.get("http://devtest.simplevoip.us/ajax_functions.php?fn=get_account_devices&accountId="+accountId)
.done((data) => {
$.each(data, (i, elem) => {
let row = `<tr style="background-color:#ccc;"><td style="border-right:1px solid #fff;">${elem.deviceId}</td><td style="border-right:1px solid #fff;">${elem.name}</td><td><button data-device-id='${elem.deviceId}' class='detail'>More Detail</button></td></tr>`
$.get("http://devtest.simplevoip.us/ajax_functions.php?fn=get_config_info&deviceId=" + elem.deviceId)
.done((data) => {
$('#michelle').append(`${row}<tr><td colspan="2"><span style="font-size:9pt; font-style:italic; font-weight:bold;">product detail</span>
<br>
<div class="row">
<div class="col-md-6 col-xs-12">
<b>mac:</b> ${data.mac}
</div>
<div class="col-md-6 col-xs-12">
<b>customer template Id:</b> ${data.customerTemplateID}
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-12">
<b>code:</b> ${data.codec}
</div>
<div class="col-md-6 col-xs-12">
<b>transport:</b> ${data.transport}
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-12">
<b>proxy:</b> ${data.proxy}
</div>
<div class="col-md-6 col-xs-12">
<b>line 2:</b> ${data.line2}
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-12">
<b>line 3:</b> ${data.line3}
</div>
<div class="col-md-6 col-xs-12">
<b>line 4:</b> ${data.line4}
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-12">
<b>config id:</b> ${data.configID}
</div>
<div class="col-md-6 col-xs-12">
<b>ip:</b> ${data.ip}
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-12">
<b>gw:</b> ${data.gw}
</div>
<div class="col-md-6 col-xs-12">
<b>subnet:</b> ${data.subnet}
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-12">
<b>algo_output:</b> ${data.algo_output}
</div>
<div class="col-md-6 col-xs-12">
<b>system log:</b> ${data.syslog}
</div>
</div>
<div class="row">
<div class="col-xs-12">
<b>last access:</b> ${data.lastAccess}
</div>
</div>
</td></tr>`)
})
})
})
.fail((error) => console.log(error))
.always(() => console.log('Done'));
});
</script>
That's the fruit of our labors yesterday. Line #38 is what I need to GET when I first open up this form. How do I implement that into this process?ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
Web development includes all aspects of presenting content on intranets and the Internet, including delivery development, protocols, languages and standards, server software, browser clients, databases and multimedia generation.
TRUSTED BY
As always, there are a number of ways to do this. First off, you're gonna want to hook an event up to your button. Because it's being created dynamically, you'll have to delegate the event to something that already exists on page load - such as your #michelle div, so something like this:
Open in new window
That will hook a click onto your button and grab the deviceId. I'm guessing that deviceId will allow you to do some kind of search / query to retrieve the values you need, so depending on how you want to get that data will dictate which is the easiest method to move forward.Basically, you will need to add the Modal functionality to your page (easy options include Bootstrap or jQueryUI). You Modal body will either contain a form, or it will contain a place holder. When you run your query, you will either populate the form fields (based on data properties returned) and then show it, or you will inject a pre-populated HTML snippet into the form (this option is probably easiest if you're making a call back to your own server - you can use PHP to run the query and generate the form).
You haven't said how you intend to query the data, so I can't give you specifics. Also, let me know whether you're planning on using jQueryUI modal or Bootstrap (or neither if you're feeling adventurous!)