add: migrate edit view (wip)

pull/9143/head
Luciano Righetti 2023-06-14 10:53:47 +02:00
parent 267e870d0e
commit 2dae54ca15
3 changed files with 301 additions and 167 deletions

View File

@ -155,28 +155,31 @@ class SharingGroupsController extends AppController
$sharingGroup = $this->SharingGroups->find(
'all',
[
'conditions' => Validation::uuid($id) ? ['SharingGroup.uuid' => $id] : ['SharingGroup.id' => $id],
'conditions' => Validation::uuid($id) ? ['SharingGroups.uuid' => $id] : ['SharingGroups.id' => $id],
'recursive' => -1,
'contain' => [
'SharingGroupOrg' => [
'Organisation' => ['name', 'local', 'id']
'SharingGroupOrgs' => [
'Organisations' => [
'fields' => ['name', 'local', 'id']
]
],
'SharingGroupServer' => [
'Server' => [
'SharingGroupServers' => [
'Servers' => [
'fields' => ['name', 'url', 'id']
]
],
'Organisation' => [
'Organisations' => [
'fields' => ['name', 'local', 'id']
],
],
]
)->disableHydration()->first();
if (empty($sharingGroup)) {
throw new NotFoundException('Invalid sharing group.');
}
if (!$this->SharingGroups->checkIfAuthorisedExtend($this->ACL->getUser(), $sharingGroup['id'])) {
if (!$this->SharingGroups->checkIfAuthorisedExtend($this->ACL->getUser()->toArray(), $sharingGroup['id'])) {
throw new MethodNotAllowedException('Action not allowed.');
}
if ($this->request->is('post')) {
@ -224,15 +227,16 @@ class SharingGroupsController extends AppController
} elseif ($this->ParamHandler->isRest()) {
return $this->RestResponse->describe('SharingGroup', 'edit', false, $this->response->getType());
}
$orgs = $this->SharingGroups->Organisation->find(
$orgs = $this->SharingGroups->Organisations->find(
'all',
[
'conditions' => ['local' => 1],
'recursive' => -1,
'fields' => ['id', 'name']
]
);
$this->set('sharingGroup', $sharingGroup);
)->disableHydration()->toArray();
$this->set('entity', $sharingGroup);
$this->set('id', $sharingGroup['id']);
$this->set('orgs', $orgs);
$this->set('localInstance', empty(Configure::read('MISP.external_baseurl')) ? Configure::read('MISP.baseurl') : Configure::read('MISP.external_baseurl'));

View File

@ -1,139 +1,156 @@
<?php
use App\Model\Entity\SharingGroup;
use Cake\Core\Configure;
?>
<div class="users form">
<fieldset>
<legend><?php echo __('Edit Sharing Group'); ?></legend>
<?php
$data = array(
'children' => array(
array(
'children' => array(
array(
'text' => __('General'),
'title' => __('General tab'),
'class' => 'progress_tab',
'id' => 'page1_tab',
'active' => true,
'onClick' => 'simpleTabPage',
'onClickParams' => array(1)
),
array(
'text' => __('Organisations'),
'title' => __('Organisations tab'),
'class' => 'progress_tab',
'id' => 'page2_tab',
'onClick' => 'simpleTabPage',
'onClickParams' => array(2)
),
array(
'text' => __('MISP Instances'),
'title' => __('MISP instances tab'),
'class' => 'progress_tab',
'id' => 'page3_tab',
'onClick' => 'simpleTabPage',
'onClickParams' => array(3)
),
array(
'text' => __('Summary and Save'),
'title' => __('Sharing group summary'),
'class' => 'progress_tab',
'id' => 'page4_tab',
'onClick' => 'simpleTabPage',
'onClickParams' => array(4)
)
)
)
)
$data = [
'children' => [
[
'children' => [
[
'text' => __('General'),
'title' => __('General tab'),
'class' => 'progress_tab',
'id' => 'page1_tab',
'active' => true,
'onClick' => 'simpleTabPage',
'onClickParams' => [1]
],
[
'text' => __('Organisations'),
'title' => __('Organisations tab'),
'class' => 'progress_tab',
'id' => 'page2_tab',
'onClick' => 'simpleTabPage',
'onClickParams' => [2]
],
[
'text' => __('MISP Instances'),
'title' => __('MISP instances tab'),
'class' => 'progress_tab',
'id' => 'page3_tab',
'onClick' => 'simpleTabPage',
'onClickParams' => [3]
],
[
'text' => __('Summary and Save'),
'title' => __('Sharing group summary'),
'class' => 'progress_tab',
'id' => 'page4_tab',
'onClick' => 'simpleTabPage',
'onClickParams' => [4]
]
]
]
],
];
if (!$ajax) {
echo $this->element(
'/genericElements/ListTopBar/scaffold',
[
'data' => $data,
'table_data' => [],
'tableRandomValue' => Cake\Utility\Security::randomString(8)
]
);
if (!$ajax) {
echo $this->element('/genericElements/ListTopBar/scaffold', array('data' => $data));
}
}
?>
<div id="page1_content" class="multi-page-form-div tabContent" style="width:544px;">
<label for="SharingGroupName"><?php echo __('Name');?></label>
<input type="text" class="input-xxlarge" placeholder="<?php echo __('Example: Multinational sharing group');?>" id="SharingGroupName" value="<?php echo h($sharingGroup['SharingGroup']['name']); ?>">
<label for="SharingGroupReleasability"><?php echo __('Releasable to');?></label>
<input type="text" class="input-xxlarge" placeholder="<?php echo __('Example: Community1, Organisation1, Organisation2');?>" id="SharingGroupReleasability" value="<?php echo h($sharingGroup['SharingGroup']['releasability']); ?>">
<label for="SharingGroupDescription"><?php echo __('Description');?></label>
<textarea class="input-xxlarge" placeholder="<?php echo __('A description of the sharing group.');?>" cols="30" rows="6" id="SharingGroupDescription"><?php echo h($sharingGroup['SharingGroup']['description']); ?></textarea>
<label for="SharingGroupName"><?php echo __('Name'); ?></label>
<input type="text" class="input-xxlarge" placeholder="<?php echo __('Example: Multinational sharing group'); ?>" id="SharingGroupName" value="<?php echo h($entity['name']); ?>">
<label for="SharingGroupReleasability"><?php echo __('Releasable to'); ?></label>
<input type="text" class="input-xxlarge" placeholder="<?php echo __('Example: Community1, Organisation1, Organisation2'); ?>" id="SharingGroupReleasability" value="<?php echo h($entity['releasability']); ?>">
<label for="SharingGroupDescription"><?php echo __('Description'); ?></label>
<textarea class="input-xxlarge" placeholder="<?php echo __('A description of the sharing group.'); ?>" cols="30" rows="6" id="SharingGroupDescription"><?php echo h($entity['description']); ?></textarea>
<div style="display:block;">
<input type="checkbox" style="float:left;" title="<?php echo __('Active sharing groups can be selected by users of the local instance when creating events. Generally, sharing groups received through synchronisation will have this disabled until manually enabled.');?>" <?php if ($sharingGroup['SharingGroup']['active']) echo "checked"; ?> id="SharingGroupActive">
<label for="SharingGroupActive" style="padding-left:20px;"><?php echo __('Make the sharing group selectable (active)');?></label>
<input type="checkbox" style="float:left;" title="<?php echo __('Active sharing groups can be selected by users of the local instance when creating events. Generally, sharing groups received through synchronisation will have this disabled until manually enabled.'); ?>" <?php if ($entity['active']) echo "checked"; ?> id="SharingGroupActive">
<label for="SharingGroupActive" style="padding-left:20px;"><?php echo __('Make the sharing group selectable (active)'); ?></label>
</div>
<span role="button" tabindex="0" aria-label="<?php echo __('Next page');?>" title="<?php echo __('Next page');?>" class="btn btn-inverse" onClick="simpleTabPage(2);"><?php echo __('Next page');?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Next page'); ?>" title="<?php echo __('Next page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(2);"><?php echo __('Next page'); ?></span>
</div>
<div id="page2_content" class="multi-page-form-div tabContent" style="display:none;width:544px;">
<div class="tabMenuFixedContainer">
<span role="button" tabindex="0" aria-label="<?php echo __('Add local organisation(s) to the sharing group');?>" title="<?php echo __('Add local organisation(s) to the sharing group');?>" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer" onClick="sharingGroupAdd('organisation', 'local');"><?php echo __('Add local organisation');?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Add remote organisations to the sharing group');?>" title="<?php echo __('Add remote organisations to the sharing group');?>" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer" onClick="sharingGroupAdd('organisation', 'remote');"><?php echo __('Add remote organisation');?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Add local organisation(s) to the sharing group'); ?>" title="<?php echo __('Add local organisation(s) to the sharing group'); ?>" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer" onClick="sharingGroupAdd('organisation', 'local');"><?php echo __('Add local organisation'); ?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Add remote organisations to the sharing group'); ?>" title="<?php echo __('Add remote organisations to the sharing group'); ?>" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer" onClick="sharingGroupAdd('organisation', 'remote');"><?php echo __('Add remote organisation'); ?></span>
</div>
<table id="organisations_table" class="table table-striped table-hover table-condensed">
<tr id="organisations_table_header">
<th><?php echo __('Type');?></th>
<th><?php echo __('Name');?></th>
<th><?php echo __('UUID');?></th>
<th><?php echo __('Extend');?></th>
<th><?php echo __('Actions');?></th>
<th><?php echo __('Type'); ?></th>
<th><?php echo __('Name'); ?></th>
<th><?php echo __('UUID'); ?></th>
<th><?php echo __('Extend'); ?></th>
<th><?php echo __('Actions'); ?></th>
</tr>
</table>
<span role="button" tabindex="0" aria-label="<?php echo __('Previous page');?>" title="<?php echo __('Previous page');?>" class="btn btn-inverse" onClick="simpleTabPage(1);"><?php echo __('Previous page');?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Next page');?>" title="<?php echo __('Next page');?>" class="btn btn-inverse" onClick="simpleTabPage(3);"><?php echo __('Next page');?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Previous page'); ?>" title="<?php echo __('Previous page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(1);"><?php echo __('Previous page'); ?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Next page'); ?>" title="<?php echo __('Next page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(3);"><?php echo __('Next page'); ?></span>
</div>
<div id="page3_content" class="multi-page-form-div tabContent" style="display:none;width:544px;">
<?php
<?php
$serverDivVisibility = "";
$checked = "";
if ($sharingGroup['SharingGroup']['roaming']) {
if ($entity['roaming']) {
$serverDivVisibility = 'style="display:none;"';
$checked = "checked";
}
?>
?>
<div style="display:block;">
<input type="checkbox" style="float:left;" title="<?php echo __('Enable roaming mode for this sharing group. Roaming mode will allow the sharing group to be passed to any instance where the remote recipient is contained in the organisation list. It is preferred to list the recipient instances instead.');?>" <?php echo $checked; ?> id="SharingGroupRoaming">
<label for="SharingGroupRoaming" style="padding-left:20px;"><?php echo __('<b>Enable roaming mode</b> for this sharing group (pass the event to any connected instance where the sync connection is tied to an organisation contained in the SG organisation list).');?></label>
<input type="checkbox" style="float:left;" title="<?php echo __('Enable roaming mode for this sharing group. Roaming mode will allow the sharing group to be passed to any instance where the remote recipient is contained in the organisation list. It is preferred to list the recipient instances instead.'); ?>" <?php echo $checked; ?> id="SharingGroupRoaming">
<label for="SharingGroupRoaming" style="padding-left:20px;"><?php echo __('<b>Enable roaming mode</b> for this sharing group (pass the event to any connected instance where the sync connection is tied to an organisation contained in the SG organisation list).'); ?></label>
</div>
<div id="serverList" <?php echo $serverDivVisibility; ?>>
<div class="tabMenuFixedContainer">
<span role="button" tabindex="0" aria-label="<?php echo __('Add instance');?>" title="<?php echo __('Add instance');?>" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer" onClick="sharingGroupAdd('server');"><?php echo __('Add instance');?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Add instance'); ?>" title="<?php echo __('Add instance'); ?>" class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer" onClick="sharingGroupAdd('server');"><?php echo __('Add instance'); ?></span>
</div>
<table id="servers_table" class="table table-striped table-hover table-condensed">
<tr>
<th><?php echo __('Name');?></th>
<th><?php echo __('URL');?></th>
<th><?php echo __('All orgs');?></th>
<th><?php echo __('Actions');?></th>
<th><?php echo __('Name'); ?></th>
<th><?php echo __('URL'); ?></th>
<th><?php echo __('All orgs'); ?></th>
<th><?php echo __('Actions'); ?></th>
</tr>
</table>
</div>
<span role="button" tabindex="0" aria-label="<?php echo __('Previous page');?>" title="<?php echo __('Previous page');?>" class="btn btn-inverse" onClick="simpleTabPage(2);"><?php echo __('Previous page');?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Next page');?>" title="<?php echo __('Next page');?>" class="btn btn-inverse" onClick="simpleTabPage(4);"><?php echo __('Next page');?></span>
</div>
<span role="button" tabindex="0" aria-label="<?php echo __('Previous page'); ?>" title="<?php echo __('Previous page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(2);"><?php echo __('Previous page'); ?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Next page'); ?>" title="<?php echo __('Next page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(4);"><?php echo __('Next page'); ?></span>
</div>
</fieldset>
<div id="page4_content" class="multi-page-form-div tabContent" style="display:none;width:544px;">
<p><?php echo __('<span class="bold">General: </span>You are about to create the <span id="summarytitle" class="red bold"></span> sharing group, which is intended to be releasable to <span id="summaryreleasable" class="red bold"></span>. </p>
<p><?php echo __(
'<span class="bold">General: </span>You are about to create the <span id="summarytitle" class="red bold"></span> sharing group, which is intended to be releasable to <span id="summaryreleasable" class="red bold"></span>. </p>
<p id="localText"><span class="bold">Local organisations: </span>It will be visible to <span id="summarylocal" class="red bold"></span>, from which <span id="summarylocalextend" class="red bold"></span> can extend the sharing group. </p>
<p id="externalText"><span class="bold">External organisations: </span>It will also be visible to <span id="summaryexternal" class="red bold"></span>, out of which <span id="summaryexternalextend" class="red bold"></span> can extend the sharing group.');?></p>
<p id="synchronisationText"><span class="bold"><?php echo __('Synchronisation: </span>Furthermore, events are automatically pushed to: <span id="summaryservers" class="red bold"></span>');?></p>
<p><?php echo __('You can edit this information by going back to one of the previous pages, or if you agree with the above mentioned information, click Submit to create the Sharing group.');?></p>
<p id="externalText"><span class="bold">External organisations: </span>It will also be visible to <span id="summaryexternal" class="red bold"></span>, out of which <span id="summaryexternalextend" class="red bold"></span> can extend the sharing group.'
); ?></p>
<p id="synchronisationText"><span class="bold"><?php echo __('Synchronisation: </span>Furthermore, events are automatically pushed to: <span id="summaryservers" class="red bold"></span>'); ?></p>
<p><?php echo __('You can edit this information by going back to one of the previous pages, or if you agree with the above mentioned information, click Submit to create the Sharing group.'); ?></p>
<?php
echo $this->Form->create('SharingGroup');
echo $this->Form->input('json', array('style' => 'display:none;', 'label' => false, 'div' => false));
//echo $this->Form->button(__('Submit'), array('class' => 'btn btn-primary'));
echo $this->Form->end();
$sharingGroup = new SharingGroup();
echo $this->Form->create($sharingGroup);
echo $this->Form->input('json', ['style' => 'display:none;', 'label' => false, 'div' => false]);
//echo $this->Form->button(__('Submit'), array('class' => 'btn btn-primary'));
echo $this->Form->end();
?>
<span role="button" tabindex="0" aria-label="<?php echo __('Previous page');?>" title="<?php echo __('Previous page');?>" class="btn btn-inverse" onClick="simpleTabPage(3);"><?php echo __('Previous page');?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Submit and create sharing group');?>" title="<?php echo __('Submit and create sharing group');?>" class="btn btn-primary" onClick="sgSubmitForm('Edit');">Submit</span>
<span role="button" tabindex="0" aria-label="<?php echo __('Previous page'); ?>" title="<?php echo __('Previous page'); ?>" class="btn btn-inverse" onClick="simpleTabPage(3);"><?php echo __('Previous page'); ?></span>
<span role="button" tabindex="0" aria-label="<?php echo __('Submit and create sharing group'); ?>" title="<?php echo __('Submit and create sharing group'); ?>" class="btn btn-primary" onClick="sgSubmitForm('Edit');">Submit</span>
</div>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'globalActions', 'menuItem' => 'editSG'));
// TODO: [3.x-MIGRATION]
// echo $this->element('/genericElements/SideMenu/side_menu', ['menuList' => 'globalActions', 'menuItem' => 'editSG']);
?>
<script type="text/javascript">
var lastPage = 4;
var organisations = [];
var orgids = ['<?php echo h($user['Organisation']['id'])?>'];
var orgids = ['<?php echo h($user['Organisation']['id']) ?>'];
var servers = [];
var serverids = [0];
<?php
if (empty($sharingGroup['SharingGroupServer'])):
if (empty($entity['SharingGroupServer'])) :
?>
var servers = [{
id: '0',
@ -143,55 +160,55 @@
removable: 0
}];
var serverids = [0];
<?php
else:
foreach ($sharingGroup['SharingGroupServer'] as $s):
?>
serverids.push(<?php echo h($s['server_id']);?>);
<?php
if ($s['server_id'] == 0):
?>
servers.push({
id: '<?php echo h($s['server_id']);?>',
name: 'Local instance',
url: '<?php echo empty(Configure::read('MISP.external_baseurl')) ? Configure::read('MISP.baseurl') : Configure::read('MISP.external_baseurl');?>',
all_orgs: '<?php echo h($s['all_orgs']); ?>',
removable:0,
});
<?php
else:
?>
servers.push({
id: '<?php echo h($s['server_id']);?>',
name: '<?php echo h($s['Server']['name']); ?>',
url: '<?php echo h($s['Server']['url']); ?>',
all_orgs: '<?php echo h($s['all_orgs']); ?>',
removable:1,
});
<?php
endif;
endforeach;
endif;
?>
<?php
foreach ($sharingGroup['SharingGroupOrg'] as $s):
?>
orgids.push(<?php echo h($s['org_id']);?>);
var removable = 1;
if (<?php echo h($sharingGroup['Organisation']['id']);?> == <?php echo h($s['org_id'])?>) removable = 0;
organisations.push({
id: '<?php echo h($s['org_id']);?>',
type: '<?php echo ($s['Organisation']['local'] == 1 ? 'local' : 'remote'); ?>',
name: '<?php echo h($s['Organisation']['name'])?>',
extend: '<?php echo h($s['extend']);?>',
uuid: '',
removable:removable
});
<?php
endforeach;
else :
foreach ($entity['SharingGroupServer'] as $s) :
?>
serverids.push(<?php echo h($s['server_id']); ?>);
<?php
if ($s['server_id'] == 0) :
?>
servers.push({
id: '<?php echo h($s['server_id']); ?>',
name: 'Local instance',
url: '<?php echo empty(Configure::read('MISP.external_baseurl')) ? Configure::read('MISP.baseurl') : Configure::read('MISP.external_baseurl'); ?>',
all_orgs: '<?php echo h($s['all_orgs']); ?>',
removable: 0,
});
<?php
else :
?>
servers.push({
id: '<?php echo h($s['server_id']); ?>',
name: '<?php echo h($s['Server']['name']); ?>',
url: '<?php echo h($s['Server']['url']); ?>',
all_orgs: '<?php echo h($s['all_orgs']); ?>',
removable: 1,
});
<?php
endif;
endforeach;
endif;
?>
<?php
foreach ($entity['SharingGroupOrg'] as $s) :
?>
orgids.push(<?php echo h($s['org_id']); ?>);
var removable = 1;
if (<?php echo h($entity['Organisation']['id']); ?> == <?php echo h($s['org_id']) ?>) removable = 0;
organisations.push({
id: '<?php echo h($s['org_id']); ?>',
type: '<?php echo ($s['Organisation']['local'] == 1 ? 'local' : 'remote'); ?>',
name: '<?php echo h($s['Organisation']['name']) ?>',
extend: '<?php echo h($s['extend']); ?>',
uuid: '',
removable: removable
});
<?php
endforeach;
?>
$(function() {
if ($('#SharingGroupJson').val()) sharingGroupPopulateFromJson();
@ -205,5 +222,4 @@
$('#serverList').show();
}
});
</script>
</script>

View File

@ -8,7 +8,7 @@ function executeStateDependencyChecks(dependenceSourceSelector) {
} else {
var tempSelector = '*[data-dependence-source="' + dependenceSourceSelector + '"]';
}
$(tempSelector).each(function(index, dependent) {
$(tempSelector).each(function (index, dependent) {
var dependenceSource = $(dependent).data('dependence-source');
if ($(dependent).data('dependence-option') === $(dependenceSource).val()) {
$(dependent).parent().parent().removeClass('d-none');
@ -30,19 +30,19 @@ function testConnection(id) {
UI.overlayUntilResolve(
$container[0],
AJAXApi.quickFetchJSON(`/broods/testConnection/${id}`),
{text: 'Running test'}
{ text: 'Running test' }
).then(result => {
const $testResult = attachTestConnectionResultHtml(result, $container)
$(`#connection_test_${id}`).append($testResult)
})
.catch((error) => {
const $testResult = attachTestConnectionResultHtml(error.message, $container)
$(`#connection_test_${id}`).append($testResult)
})
.catch((error) => {
const $testResult = attachTestConnectionResultHtml(error.message, $container)
$(`#connection_test_${id}`).append($testResult)
})
}
function attachTestConnectionResultHtml(result, $container) {
function getKVHtml(key, value, valueClasses=[], extraValue='') {
function getKVHtml(key, value, valueClasses = [], extraValue = '') {
return $('<div/>').append(
$('<strong/>').text(key + ': '),
$('<span/>').addClass(valueClasses).text(value),
@ -84,15 +84,15 @@ function syntaxHighlightJson(json, indent) {
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'text-info';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'text-primary';
} else {
cls = '';
}
if (/:$/.test(match)) {
cls = 'text-primary';
} else {
cls = '';
}
} else if (/true|false/.test(match)) {
cls = 'text-info';
cls = 'text-info';
} else if (/null/.test(match)) {
cls = 'text-danger';
cls = 'text-danger';
}
return '<span class="' + cls + '">' + match + '</span>';
});
@ -103,10 +103,10 @@ function getTextColour(hex) {
return 'black'
}
hex = hex.slice(1)
var r = parseInt(hex.substring(0,2), 16)
var g = parseInt(hex.substring(2,4), 16)
var b = parseInt(hex.substring(4,6), 16)
var avg = ((2 * r) + b + (3 * g))/6
var r = parseInt(hex.substring(0, 2), 16)
var g = parseInt(hex.substring(2, 4), 16)
var b = parseInt(hex.substring(4, 6), 16)
var avg = ((2 * r) + b + (3 * g)) / 6
if (avg < 128) {
return 'white'
} else {
@ -131,7 +131,7 @@ function performGlobalSearch(evt) {
return;
}
const endpoint = '/instance/searchAll'
const searchParams = new URLSearchParams({search: value});
const searchParams = new URLSearchParams({ search: value });
const url = endpoint + '?' + searchParams
const options = {
statusNode: $resultContainer.find('.search-results-wrapper')
@ -171,7 +171,7 @@ function openSaveBookmarkModal(bookmark_url = '') {
})
}
function deleteBookmark(bookmark, forSidebar=false) {
function deleteBookmark(bookmark, forSidebar = false) {
const url = '/user-settings/deleteMyBookmark'
AJAXApi.quickFetchAndPostForm(url, {
bookmark_name: bookmark.name,
@ -315,10 +315,124 @@ $(document).ready(() => {
const url = `/user-settings/setMySetting/${settingName}`
AJAXApi.quickFetchAndPostForm(url, {
value: expanded ? 0 : 1
}, { provideFeedback: false})
}, { provideFeedback: false })
})
$('.sidebar #btn-add-bookmark').click(() => {
openSaveBookmarkModal(window.location.pathname)
})
})
function simpleTabPage(page) {
$(".progress_tab").removeClass("btn-primary").addClass("btn-inverse");
$("#page" + page + "_tab").removeClass("btn-inverse").addClass("btn-primary");
$(".tabContent").hide();
$("#page" + page + "_content").show();
if (page == lastPage) simpleTabPageLast();
}
function simpleTabPageLast() {
var summaryorgs = summaryextendorgs = remotesummaryorgs = remotesummaryextendorgs = summaryservers = "";
var orgcounter = extendcounter = remoteorgcounter = remoteextendcounter = servercounter = 0;
var sgname = "[Sharing group name not set!]";
if ($('#SharingGroupName').val()) sgname = $('#SharingGroupName').val();
var sgreleasability = "[Sharing group releasability not set!]";
if ($('#SharingGroupReleasability').val()) sgreleasability = $('#SharingGroupReleasability').val();
$('#summarytitle').text(sgname);
$('#summaryreleasable').text(sgreleasability);
organisations.forEach(function (organisation) {
if (organisation.type == 'local') {
if (orgcounter > 0) summaryorgs += ", ";
summaryorgs += organisation.name;
if (organisation.extend == true) {
if (extendcounter > 0) summaryextendorgs += ", "
summaryextendorgs += organisation.name;
extendcounter++;
}
orgcounter++;
} else {
if (remoteorgcounter > 0) remotesummaryorgs += ", ";
remotesummaryorgs += organisation.name;
if (organisation.extend == true) {
if (remoteextendcounter > 0) remotesummaryextendorgs += ", "
remotesummaryextendorgs += organisation.name;
remoteextendcounter++;
}
remoteorgcounter++;
}
});
if (orgcounter == 0) $('#localText').hide();
if (remoteorgcounter == 0) $('#externalText').hide();
if (extendcounter == 0) summaryextendorgs = "nobody";
if (remoteextendcounter == 0) remotesummaryextendorgs = "nobody";
servers.forEach(function (server) {
if (servercounter > 0) summaryservers += ", ";
if (server.id != 0) {
summaryservers += server.name;
if (extendcounter == 0) summaryextendorgs = "none";
servercounter++;
}
if (server.id == 0 && server.all_orgs == true) summaryorgs = "all organisations on this instance";
});
if ($('#SharingGroupRoaming').is(":checked")) {
summaryservers = "any interconnected instances linked by an eligible organisation.";
} else {
if (servercounter == 0) {
summaryservers = "data marked with this sharing group will not be pushed.";
}
}
$('#summarylocal').text(summaryorgs);
$('#summarylocalextend').text(summaryextendorgs);
$('#summaryexternal').text(remotesummaryorgs);
$('#summaryexternalextend').text(remotesummaryextendorgs);
$('#summaryservers').text(summaryservers);
}
function sharingGroupPopulateOrganisations() {
$('input[id=SharingGroupOrganisations]').val(JSON.stringify(organisations));
$('.orgRow').remove();
var id = 0;
var html = '';
organisations.forEach(function (org) {
html = '<tr id="orgRow' + id + '" class="orgRow">';
html += '<td class="short">' + org.type + '&nbsp;</td>';
html += '<td>' + $('<div>').text(org.name).html() + '&nbsp;</td>';
html += '<td>' + org.uuid + '&nbsp;</td>';
html += '<td class="short" style="text-align:center;">';
if (org.removable == 1) {
html += '<input id="orgExtend' + id + '" type="checkbox" onClick="sharingGroupExtendOrg(' + id + ')" ';
if (org.extend) html += 'checked';
html += '>';
} else {
html += '<span class="icon-ok"></span>'
}
html += '</td>';
html += '<td class="actions short">';
if (org.removable == 1) html += '<span class="icon-trash" onClick="sharingGroupRemoveOrganisation(' + id + ')"></span>';
html += '&nbsp;</td></tr>';
$('#organisations_table tr:last').after(html);
id++;
});
}
function sharingGroupPopulateServers() {
$('input[id=SharingGroupServers]').val(JSON.stringify(servers));
$('.serverRow').remove();
var id = 0;
var html = '';
servers.forEach(function (server) {
html = '<tr id="serverRow' + id + '" class="serverRow">';
html += '<td>' + server.name + '&nbsp;</td>';
html += '<td>' + server.url + '&nbsp;</td>';
html += '<td>';
html += '<input id="serverAddOrgs' + id + '" type="checkbox" onClick="sharingGroupServerAddOrgs(' + id + ')" ';
if (server.all_orgs) html += 'checked';
html += '>';
html += '</td>';
html += '<td class="actions short">';
if (server.removable == 1) html += '<span class="icon-trash" onClick="sharingGroupRemoveServer(' + id + ')"></span>';
html += '&nbsp;</td></tr>';
$('#servers_table tr:last').after(html);
id++;
});
}