Skip to content

Commit

Permalink
Improve configure target settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcrankhank committed Nov 10, 2015
1 parent b6f0f90 commit d22348c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 61 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ In version 0.7:
- [ ] Display input validation with bootstrap css Validation states (http://formvalidation.io/validators/integer/)
- [ ] Bootstrap-table Table Select Checkbox
- [ ] Awesome checkboxes (https://github.com/designmodo/Flat-UI)
- [ ] Improve configure target settings menu
- [ ] Improve nested table row handling
- [ ] Add target and lvm name to url
- [ ] Overview/Logical volumes VG selector
Expand Down
19 changes: 4 additions & 15 deletions app/controllers/targets.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,12 @@ public function configure($param1 = false, $param2 = false) {
}
} else if ($param1 == 'settings') {
if (isset($_POST['option'], $_POST['newvalue'], $_POST['iqn'])) {
$iqn = filter_input(INPUT_POST, 'iqn', FILTER_SANITIZE_STRING);
$option = filter_input(INPUT_POST, 'option', FILTER_SANITIZE_STRING);
$newvalue = filter_input(INPUT_POST, 'newvalue', FILTER_SANITIZE_STRING);

$target = $this->model('target\Target', $iqn);
$target->add_setting($option, $newvalue);
$target = $this->model('target\Target', filter_input(INPUT_POST, 'iqn', FILTER_SANITIZE_STRING));
$target->add_setting($option = filter_input(INPUT_POST, 'option', FILTER_SANITIZE_STRING), filter_input(INPUT_POST, 'newvalue', FILTER_SANITIZE_STRING));
echo json_encode($target->logging->get_action_result());
} else if (isset($_POST['iqn'])) {
$iqn = filter_input(INPUT_POST, 'iqn', FILTER_SANITIZE_STRING);

$target = $this->model('target\Target', $iqn);
$data = $target->get_all_settings();
// cut array in two pieces
$len = count($data);
$view_data[0] = array_slice($data, 0, $len / 2);
$view_data[1] = array_slice($data, $len / 2);
$this->view('targets/settings_table', $view_data);
$target = $this->model('target\Target', filter_input(INPUT_POST, 'iqn', FILTER_SANITIZE_STRING));
$this->view('targets/settings_table', $target->get_all_settings());
}
} else if ($param1 == 'addrule') {
if (isset($_POST['iqn'], $_POST['type'], $_POST['id'])) {
Expand Down
70 changes: 32 additions & 38 deletions app/views/targets/settings_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,38 @@
<li><a href='#'>Configure</a></li>
<li class='active'>Settings</li>
</ol>
<div class="row">
<?php foreach ($data as $tables) { ?>
<div class="col-md-6">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Save</th>
<th>Option</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<?php foreach ($tables as $row) { ?>
<tr id="<?php echo htmlspecialchars($row['option']); ?>">
<td hidden><input class="settingstablecheckbox" type="checkbox"></td>
<td><a href="#" class="savevalueinput"><span class="glyphicon glyphicon-save glyphicon-20"></span></a></td>
<?php if ($row['type'] == 'input') { ?>
<td class="option"><?php echo htmlspecialchars($row['option']); ?></td>
<td><input class="value <?php if ($row['defaultvalue'] !== 'false') echo 'required' ?>" <?php if ($row['state'] == 0) echo 'disabled' ?> type="number" value="<?php if ($row['defaultvalue'] !== 'false') echo htmlspecialchars($row['defaultvalue']); ?>"></td>
<td hidden><input class="default_value_before_change" type="text" value="<?php if ($row['defaultvalue'] !== 'false') echo htmlspecialchars($row['defaultvalue']); ?>"></td>
<?php } else if ($row['type'] == 'select') { ?>
<td class="option"><?php echo htmlspecialchars($row['option']); ?></td>
<td>
<select class="optionselector" <?php if ($row['state'] == 0) echo 'disabled' ?>>
<option><?php echo htmlspecialchars($row['defaultvalue']); ?></option>
<option><?php echo htmlspecialchars($row['othervalue1']); ?></option>
</select>
</td>
<td hidden><input class="default_value_before_change" type="text" value="<?php echo htmlspecialchars($row['defaultvalue']); ?>"></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<?php } ?>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Save</th>
<th>Option</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<?php foreach ($data as $row) { ?>
<tr id="<?php echo htmlspecialchars($row['option']); ?>">
<td hidden><input class="settingstablecheckbox" type="checkbox"></td>
<td><a href="#" class="savevalueinput"><span class="glyphicon glyphicon-save glyphicon-20"></span></a></td>
<?php if ($row['type'] == 'input') { ?>
<td class="option"><?php echo htmlspecialchars($row['option']); ?></td>
<td><input class="value form-control <?php if ($row['defaultvalue'] !== 'false') echo 'required' ?>" <?php if ($row['state'] == 0) echo 'disabled' ?> value="<?php if ($row['defaultvalue'] !== 'false') echo htmlspecialchars($row['defaultvalue']); ?>"></td>
<td hidden><input class="default_value_before_change" type="text" value="<?php if ($row['defaultvalue'] !== 'false') echo htmlspecialchars($row['defaultvalue']); ?>"></td>
<?php } else if ($row['type'] == 'select') { ?>
<td class="option"><?php echo htmlspecialchars($row['option']); ?></td>
<td>
<select class="optionselector form-control" <?php if ($row['state'] == 0) echo 'disabled' ?>>
<option><?php echo htmlspecialchars($row['defaultvalue']); ?></option>
<option><?php echo htmlspecialchars($row['othervalue1']); ?></option>
</select>
</td>
<td hidden><input class="default_value_before_change" type="text" value="<?php echo htmlspecialchars($row['defaultvalue']); ?>"></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
Expand Down
22 changes: 15 additions & 7 deletions public/js/pages/target/settings.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
define(['jquery', 'mylibs', 'sweetalert', 'qtip', 'once'], function ($, mylibs, swal, qtip, once) {
define(['jquery', 'mylibs', 'sweetalert', 'once', 'touchspin'], function ($, mylibs, swal, once, touchspin) {
var methods;

return methods = {
add_event_handler_settings_table_checkbox: function () {
$('.value').once('input', function () {
var value = $('.value');

value.TouchSpin({
verticalbuttons: true,
verticalupclass: 'glyphicon glyphicon-plus',
verticaldownclass: 'glyphicon glyphicon-minus',
max: 10000000
});

value.once('input', function () {
var $this = $(this);
var $this_row = $this.closest('tr');
var oldvalue = $this_row.find('.default_value_before_change').val();
Expand All @@ -19,12 +28,11 @@ define(['jquery', 'mylibs', 'sweetalert', 'qtip', 'once'], function ($, mylibs,
},
add_event_handler_save_value: function () {
$('.savevalueinput').once('click', function () {
var this_row = $(this).closest('tr');

var newvalue;
var type;
var this_row = $(this).closest('tr'),
newvalue,
type,
oldvalue = this_row.find('.default_value_before_change').val();

var oldvalue = this_row.find('.default_value_before_change').val();
newvalue = this_row.find('.value').val();

// If value is not defined
Expand Down

0 comments on commit d22348c

Please sign in to comment.