$(document).ready(function(){ var theBlock = $('#tab-accountSettings') var mqttList = $('#mqttout_list') function drawMqttLsitRow(row){ row = row ? row : { host: '', pubKey: '', msgFor: [], monitors: [], } var selecteEventsHtml = '' $.each([ { value: 'onMonitorSave', label: lang['Monitor Edit'], }, { value: 'onMonitorStart', label: lang['Monitor Start'], }, { value: 'onMonitorStop', label: lang['Monitor Stop'], }, { value: 'onMonitorDied', label: lang['Monitor Died'], }, { value: 'onEventTrigger', label: lang['Detection Event'], }, { value: 'onDetectorNoTriggerTimeout', label: lang['No Trigger'], }, { value: 'onAccountSave', label: lang['Account Save'], }, { value: 'onUserLog', label: lang['User Log'], }, { value: 'onTwoFactorAuthCodeNotification', label: lang['2-Factor Authentication'], }, ],function(n,option){ selecteEventsHtml += createOptionHtml({ value: option.value, label: option.label, selected: row.msgFor.indexOf(option.value) > -1, }) }) var html = `
` return html } theBlock.find('.mqtt-out-add-row').click(function(){ mqttList.append(drawMqttLsitRow()) }); mqttList.on('click','.mqtt-out-delete-row',function(){ $(this).parents('.mqtt-out-list-row').remove() }); accountSettings.onLoadFields(function(theForm){ var mqttClientList = $user.details.mqttout_list ? $user.details.mqttout_list : [] mqttList.html(`
`) setTimeout(function(){ var html = '' $.each(mqttClientList,function(n,row){ html += `${drawMqttLsitRow(row,n)}` }) mqttList.html(html) },3000) }) accountSettings.onSaveFields(function(theForm){ var mqttClientList = [] mqttList.find('.mqtt-out-list-row').each(function(n,v){ var el = $(v) var rowFields = {} el.find('[mqtt-param]').each(function(nn,param){ var paramEl = $(param) var theKey = paramEl.attr('mqtt-param') var value = paramEl.val() rowFields[theKey] = value }) mqttClientList.push(rowFields) }) theForm.details.mqttout_list = mqttClientList }) })