diff --git a/index.html b/index.html old mode 100644 new mode 100755 index f901c6c8..f08d298c --- a/index.html +++ b/index.html @@ -586,15 +586,25 @@ type: "GET", url: "/admin/getClientConfig?clientId=template_" + template, dataType:"json", - success: function(jsonClientConfig) { + success: function(jsonTemplate) { table.rows({ selected: true }).eq(0).each(function (index) { var row = table.row(index); var data = row.data(); var clientId = data['client_status']['client_id']; - jsonClientConfig['cc-client']['worker-id'] = clientId + if ($('#mergeTemplate').prop('checked')) { + setMergedClientConfig(jsonTemplate, clientId); + } else { + jsonTemplate['cc-client']['worker-id'] = clientId - setClientConfig(clientId, JSON.stringify(jsonClientConfig,undefined, 2)); + clientConfig = jsonJSON.stringify(jsonTemplate,undefined, 2); + + if ($('#replaceWorkerId').prop('checked')) { + clientConfig = clientConfig.replace(new RegExp("@WORKER-ID@", 'g'), clientId).trim(); + } + + setClientConfig(clientId, clientConfig); + } }); }, error: function (data) { @@ -666,6 +676,28 @@ return data; } + function setMergedClientConfig(template, clientId) { + $.ajax({ + type: "GET", + url: "/admin/getClientConfig?clientId=" + clientId, + dataType:"json", + success: function(clientConfig) { + $.extend(true, clientConfig, template); + + clientConfig = JSON.stringify(clientConfig,undefined, 2) + + if ($('#replaceWorkerId').prop('checked')) { + clientConfig = clientConfig.replace(new RegExp("@WORKER-ID@", 'g'), clientId).trim(); + } + + setClientConfig(clientId, clientConfig); + }, + error: function (data) { + setError('Unable to fetch client config ' + clientId + ' for template merge - Please make sure it readable!'); + } + }); + } + function laststatus( data, type, row ) { if (type !== 'sort') { var date = new Date(data*1000 - clockDrift); @@ -988,6 +1020,16 @@