dfgfdg
This commit is contained in:
12
public/assets/bt/crud/README.md
Normal file
12
public/assets/bt/crud/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
## CRUD Bootstrap Table Example
|
||||
|
||||
* Install
|
||||
```
|
||||
# linux maybe you need sudo
|
||||
npm install -g json-server
|
||||
```
|
||||
|
||||
* Run
|
||||
```
|
||||
json-server -p 3001 db.json
|
||||
```
|
||||
39
public/assets/bt/crud/db.json
Normal file
39
public/assets/bt/crud/db.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"list": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "bootstrap-table",
|
||||
"stargazers_count": 2156,
|
||||
"forks_count": 633,
|
||||
"description": "An extended Bootstrap table with radio, checkbox, sort, pagination, and other added features."
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "multiple-select",
|
||||
"stargazers_count": 660,
|
||||
"forks_count": 260,
|
||||
"description": "A jQuery plugin to select multiple elements with checkboxes :)"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "bootstrap-table-examples",
|
||||
"stargazers_count": 133,
|
||||
"forks_count": 107,
|
||||
"description": "Bootstrap table examples"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "bootstrap-show-password",
|
||||
"stargazers_count": 67,
|
||||
"forks_count": 28,
|
||||
"description": "Show/hide password plugin for twitter bootstrap."
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"name": "blog",
|
||||
"stargazers_count": 22,
|
||||
"forks_count": 11,
|
||||
"description": "my blog"
|
||||
}
|
||||
]
|
||||
}
|
||||
187
public/assets/bt/crud/index.html
Normal file
187
public/assets/bt/crud/index.html
Normal file
@@ -0,0 +1,187 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CRUD Table</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="../assets/bootstrap/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="../assets/bootstrap-table/src/bootstrap-table.css">
|
||||
<link rel="stylesheet" href="../assets/examples.css">
|
||||
<style>
|
||||
.update {
|
||||
color: #333;
|
||||
margin-right: 5px;
|
||||
}
|
||||
.remove {
|
||||
color: red;
|
||||
margin-left: 5px;
|
||||
}
|
||||
.alert {
|
||||
padding: 0 14px;
|
||||
margin-bottom: 0;
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
<script src="../assets/jquery.min.js"></script>
|
||||
<script src="../assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script src="../assets/bootstrap-table/src/bootstrap-table.js"></script>
|
||||
<script src="../ga.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>CRUD Table</h1>
|
||||
<p class="toolbar">
|
||||
<a class="create btn btn-default" href="javascript:">Create Item</a>
|
||||
<span class="alert"></span>
|
||||
</p>
|
||||
<table id="table"
|
||||
data-show-refresh="true"
|
||||
data-show-columns="true"
|
||||
data-search="true"
|
||||
data-query-params="queryParams"
|
||||
data-toolbar=".toolbar">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-field="name">Name</th>
|
||||
<th data-field="stargazers_count">Stars</th>
|
||||
<th data-field="forks_count">Forks</th>
|
||||
<th data-field="description">Description</th>
|
||||
<th data-field="action"
|
||||
data-align="center"
|
||||
data-formatter="actionFormatter"
|
||||
data-events="actionEvents">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="modal" class="modal fade">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title"></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" name="name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Stars</label>
|
||||
<input type="number" class="form-control" name="stargazers_count" placeholder="Stars">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Forks</label>
|
||||
<input type="number" class="form-control" name="forks_count" placeholder="Forks">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<input type="text" class="form-control" name="description" placeholder="Description">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary submit">Submit</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
<script>
|
||||
|
||||
var API_URL = 'http://' + location.host + ':3001/list/';
|
||||
|
||||
var $table = $('#table').bootstrapTable({url: API_URL}),
|
||||
$modal = $('#modal').modal({show: false}),
|
||||
$alert = $('.alert').hide();
|
||||
|
||||
$(function () {
|
||||
// create event
|
||||
$('.create').click(function () {
|
||||
showModal($(this).text());
|
||||
});
|
||||
|
||||
$modal.find('.submit').click(function () {
|
||||
var row = {};
|
||||
|
||||
$modal.find('input[name]').each(function () {
|
||||
row[$(this).attr('name')] = $(this).val();
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: API_URL + ($modal.data('id') || ''),
|
||||
type: $modal.data('id') ? 'put' : 'post',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(row),
|
||||
success: function () {
|
||||
$modal.modal('hide');
|
||||
$table.bootstrapTable('refresh');
|
||||
showAlert(($modal.data('id') ? 'Update' : 'Create') + ' item successful!', 'success');
|
||||
},
|
||||
error: function () {
|
||||
$modal.modal('hide');
|
||||
showAlert(($modal.data('id') ? 'Update' : 'Create') + ' item error!', 'danger');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function queryParams(params) {
|
||||
return {};
|
||||
}
|
||||
|
||||
function actionFormatter(value) {
|
||||
return [
|
||||
'<a class="update" href="javascript:" title="Update Item"><i class="glyphicon glyphicon-edit"></i></a>',
|
||||
'<a class="remove" href="javascript:" title="Delete Item"><i class="glyphicon glyphicon-remove-circle"></i></a>',
|
||||
].join('');
|
||||
}
|
||||
|
||||
// update and delete events
|
||||
window.actionEvents = {
|
||||
'click .update': function (e, value, row) {
|
||||
showModal($(this).attr('title'), row);
|
||||
},
|
||||
'click .remove': function (e, value, row) {
|
||||
if (confirm('Are you sure to delete this item?')) {
|
||||
$.ajax({
|
||||
url: API_URL + row.id,
|
||||
type: 'delete',
|
||||
success: function () {
|
||||
$table.bootstrapTable('refresh');
|
||||
showAlert('Delete item successful!', 'success');
|
||||
},
|
||||
error: function () {
|
||||
showAlert('Delete item error!', 'danger');
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function showModal(title, row) {
|
||||
row = row || {
|
||||
id: '',
|
||||
name: '',
|
||||
stargazers_count: 0,
|
||||
forks_count: 0,
|
||||
description: ''
|
||||
}; // default row value
|
||||
|
||||
$modal.data('id', row.id);
|
||||
$modal.find('.modal-title').text(title);
|
||||
for (var name in row) {
|
||||
$modal.find('input[name="' + name + '"]').val(row[name]);
|
||||
}
|
||||
$modal.modal('show');
|
||||
}
|
||||
|
||||
function showAlert(title, type) {
|
||||
$alert.attr('class', 'alert alert-' + type || 'success')
|
||||
.html('<i class="glyphicon glyphicon-check"></i> ' + title).show();
|
||||
setTimeout(function () {
|
||||
$alert.hide();
|
||||
}, 3000);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user