Update index_m.html

This commit is contained in:
2018-09-26 09:38:30 +08:00
parent c9079ed0bb
commit 729b72c2fe
+246
View File
@@ -46,6 +46,252 @@
$.each($('.modbus-grid'), function () {
var _id = $(this).attr('id');
var fields = [
{name: '_address' , title: _('Address'), type: 'text', width: '110px', sorter: 'number'},
{name: 'deviceId' , title: _('deviceId'), type: 'text', width: '60px', sorter: 'number'},
{name: 'name' , title: _('Name'), type: 'text', width: '*'},
{name: 'description', title: _('Description'), type: 'text', width: '*'},
{name: 'unit' , title: _('Unit'), type: 'text', width: '50px'},
{name: 'type' , title: _('Type'), type: 'select', width: '200px', items: typeItems, valueField: 'value', textField: 'text'},
{name: 'len' , title: _('Length'), type: 'text', width: '50px'},
{name: 'factor' , title: _('Factor'), type: 'text', width: '50px'},
{name: 'offset' , title: _('Offset'), type: 'text', width: '50px'},
{name: 'role' , title: _('Role'), type: 'select', width: '100px', items: roleItems, valueField: 'value', textField: 'text'},
{name: 'room' , title: _('Room'), type: 'select', width: '100px', items: roomsItems, valueField: 'value', textField: 'text'},
{name: 'poll' , title: _('poll'), type: 'checkbox', width: '35px'},
{name: 'wp' , title: _('WP'), type: 'checkbox', width: '35px'},
{name: 'cw' , title: _('CW'), type: 'checkbox', width: '35px'},
{ type: 'control', width: '80px'}
];
fields.splice(11, 3);
fields.splice(4, 5);
var g = $('#' + _id).jsGrid({
width: 'auto',
height: 'auto',
inserting: true,
editing: true,
sorting: true,
heading: true,
paging: false,
deleteConfirm: function (el, item, cb) {
if (!ignoreDialog || Date.now() - ignoreDialog > 60000) {
var buttons = {};
buttons[_('Delete')] = function() {
if ($('#delete_ignore_dialog').prop('checked')) {
ignoreDialog = Date.now();
}
cb && cb(true);
$( this ).dialog('close');
};
buttons[_('Cancel')] = function() {
cb && cb(false);
$( this ).dialog('close');
};
$('#delete_ignore_dialog').prop('checked', false);
$("#delete-dlg").dialog({
resizable: false,
height: 'auto',
title: _('Delete address'),
width: 500,
modal: true,
buttons: buttons
});
} else {
cb && cb(true);
}
},
data: data[_id.split('_')[1]],
fields: fields,
editRowRenderer: function(item) {
var $result = $('<tr>').addClass(this.editRowClass);
this._eachField(function(field) {
$('<td>').addClass(field.css)
.appendTo($result)
.append(field.editTemplate ? field.editTemplate(item ? item[field.name] : '', item) : '')
.width(field.width || 'auto').keypress(function (e) {
if (e.which === 13) {
$('#' + _id).jsGrid('updateItem');
}
onchange();
});
});
return $result;
},
onItemUpdated: function (obj) {
/* {grid, row, item, itemIndex, previousItem}*/
var id = obj.grid._body.parent().attr('id');
var changed = false;
if (obj.item.wp && !obj.item.poll) {
obj.item.poll = true;
changed = true;
}
if (parseInt(obj.item.address, 10).toString() !== obj.item.address.toString()) changed = true;
obj.item._address = parseInt(obj.item._address, 10);
if ($('#modbus_showAliases').prop('checked')) {
var isDirect = $('#modbus_directAddresses').prop('checked');
obj.item.address = alias2address(id.split('_').pop(), obj.item._address, isDirect);
} else {
obj.item.address = obj.item._address;
}
if (obj.item.type === '') {
obj.item.type = typeItems[1].value;
changed = true;
}
// update length
if (obj.item.type === 'string' || obj.item.type === 'stringle') {
if (obj.item.factor !== '') {
obj.item.factor = '';
changed = true;
}
if (obj.item.offset !== '') {
obj.item.offset = '';
changed = true;
}
obj.item.len = parseInt(obj.item.len, 10) || 0;
if (!obj.item.len) {
obj.item.len = 2;
changed = true;
}
} else if (typeItemsLen[obj.item.type]) {
obj.item.len = parseInt(obj.item.len, 10);
if (obj.item.len != typeItemsLen[obj.item.type]) {
obj.item.len = typeItemsLen[obj.item.type];
changed = true;
}
if (parseFloat(obj.item.factor).toString() !== obj.item.factor.toString()) {
obj.item.factor = parseFloat(obj.item.factor) || 1;
changed = true;
}
if (parseFloat(obj.item.offset).toString() !== obj.item.offset.toString()) {
obj.item.offset = parseFloat(obj.item.offset) || 0;
changed = true;
}
}
if (!obj.item.role && obj.item.type !== 'string' && obj.item.type !== 'stringle') {
if (id === 'modbus_disInputs') {
obj.item.role = 'status';
} else if (id === 'modbus_coils') {
obj.item.role = 'button';
} else if (id === 'modbus_inputRegs') {
obj.item.role = 'value';
} else if (id === 'modbus_holdingRegs') {
obj.item.role = 'level';
}
changed = true;
}
if (changed) this.render();
onchange();
},
onItemInserting: function (obj) {
if (obj.item.poll !== undefined) {
obj.item.poll = true;
}
// find automatically next address
var id = obj.grid._body.parent().attr('id').split('_')[1];
if (data[id].length) {
var max = 0;
obj.item.role = data[id][data[id].length - 1].role;
obj.item.poll = data[id][data[id].length - 1].poll;
obj.item.wp = data[id][data[id].length - 1].wp;
obj.item.cw = data[id][data[id].length - 1].cw;
obj.item.type = data[id][data[id].length - 1].type;
obj.item.len = data[id][data[id].length - 1].len;
obj.item.factor = data[id][data[id].length - 1].factor;
obj.item.offset = data[id][data[id].length - 1].offset;
obj.item.deviceId = data[id][data[id].length - 1].deviceId;
var len;
var defaultDeviceId = parseInt($('#modbus_deviceId').val(), 10) || 1;
var actualDeviceId = parseInt(obj.item.deviceId, 10);
if (!actualDeviceId) actualDeviceId = defaultDeviceId;
for (var a = 0; a < data[id].length; a++) {
var deviceId = parseInt(data[id][a].deviceId, 10);
if (!deviceId) deviceId = defaultDeviceId;
if (deviceId !== actualDeviceId) continue;
if (!obj.item.type) {
len = 1;
} else if (obj.item.type !== 'string' && obj.item.type !== 'stringle') {
len = typeItemsLen[obj.item.type];
} else {
len = obj.item.len;
}
data[id][a]._address = parseInt(data[id][a]._address, 10);
if (data[id][a]._address + len > max) max = data[id][a]._address + len;
}
obj.item._address = max;
if ($('#modbus_showAliases').prop('checked')) {
obj.item.address = alias2address(id, parseInt(obj.item._address, 10), isDirect);
} else {
obj.item.address = obj.item._address;
}
} else {
if ($('#modbus_showAliases').prop('checked')) {
if (id === 'disInputs') {
obj.item._address = data.params.disInputsOffset;
} else if (id === 'coils') {
obj.item._address = data.params.coilsOffset;
} else if (id === 'inputRegs') {
obj.item._address = data.params.inputRegsOffset;
} else if (id === 'holdingRegs') {
obj.item._address = data.params.holdingRegsOffset;
}
obj.item.address = alias2address(id, obj.item._address, isDirect);
} else {
obj.item.address = 0;
obj.item._address = 0;
}
if (id === 'inputRegs' || 'holdingRegs') {
obj.item.factor = 1;
obj.item.offset = 0;
obj.item.type = 'uint16be';
obj.item.len = '';
}
}
onchange();
},
onItemDeleted: function (obj) {
onchange();
}
});
g.data('JSGrid')._editRow = function($row) {
if(this._editingRow) {
this.updateItem();
}
var item = $row.data('JSGridItem');
if (!item) return;
var $editRow = this._createEditRow(item);
this._editingRow = $row;
$row.hide();
$editRow.insertAfter($row);
$row.data('JSGridEditRow', $editRow);
};
});
}