//update function updateById(list, item) { return updateListItem(list, item, 'id'); } function updateByNumber(list, item) { return updateListItem(list, item, 'number'); } function updateByKey(list, item) { return updateListItem(list, item, 'key'); } function updateListItem(list, item, key) { key = key || 'number'; var result = false; var to = Enumerable.from(list).where(function (o) { return o[key] === item[key]; }).firstOrDefault(); if (to) { copy(item, to); } else { list.push(item); result = true; } console.log(result?'insert':'update'+' data by '+key); return result; } //delete function remove(list, item,key) { var result = false; for (var i = 0; i < list.length; i++) { if (list[i][key] === item[key]) { list.splice(i, 1); result = true; break; } } return result; } //util function copy(from, to) { for (var attr in to) { if (from.hasOwnProperty(attr)) { if (!(from[attr] instanceof Array)) { to[attr] = from[attr]; } } } } // toastr.options = { "positionClass": "toast-top-center", "timeOut": "1000" }; var loading = { show: function (msg) { toastr.info(msg || "loading"); }, hide: function () { toastr.remove(); } }; // function execApi(number, method, query) { loading.show(); axios.post('/IoTCenter/api/v1/api/execApi', { connectionId, number, method, query }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) .finally(function () { loading.hide(); }); } function execScene(id) { loading.show(); axios.post('/IoTCenter/api/v1/api/execScene', '"' + id + '"', { headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) .finally(function () { loading.show(); }); } function nodePower(number,command) { loading.show(); axios.post('/IoTCenter/api/v1/node/power'+command, '"' + number + '"', { headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) .finally(function () { loading.show(); }); } // function Select(e) { var checkbox = $(e.target); if (checkbox.hasClass('checkall')) { if (e.target.checked) { $('input.item:visible').not(':checked').prop("checked", true); } else { $('input.item:visible').filter(':checked').prop("checked", false); } } else if (checkbox.hasClass('uncheck')) { $('input.item:visible').each(function () { $(this).prop("checked", !$(this).prop("checked")).change(); }); } var parent = $('input.checkall'); if ($('input.item').not(':checked').length === 0) { parent.prop("indeterminate", false); parent.prop("checked", true); } else if ($('input.item').filter(':checked').length === 0) { parent.prop("indeterminate", false); parent.prop("checked", false); } else { parent.prop("indeterminate", true); } }