chg: [decaying:base_score] Custom tagging in base score examples

pull/5032/head
mokaddem 2019-07-03 16:04:36 +02:00
parent 76cddeb264
commit 2d7643ccd7
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 47 additions and 5 deletions

View File

@ -2,7 +2,7 @@
<div class="span8" style="height: calc(90vh); overflow-y: scroll; border: 1px solid #ddd;">
<input id="table_taxonomy_search" class="input" style="width: 250px; margin: 0px;" type="text" placeholder="<?php echo _('Search Taxonomy'); ?>"></input>
<it class="fa fa-times useCursorPointer" title="<?php echo __('Clear search field'); ?>" onclick="$('#table_taxonomy_search').val('').trigger('input');"></it>
<span style="float: right;"><b><?php echo h($taxonomies_not_having_numerical_value); ?></b><?php echo __(' not having numerical value'); ?></span>
<span style="float: right; margin-top: 6px;" class="badge badge-info"><b><?php echo h($taxonomies_not_having_numerical_value); ?></b><?php echo __(' not having numerical value'); ?></span>
<table id="tableTaxonomy" class="table table-striped table-bordered table-condensed">
<thead>
<tr>
@ -70,8 +70,8 @@
</td>
<td>
<div style="width:100%;display:inline-block;" data-original-title="" title="">
<div style="float:left" data-original-title="" title="">
<button id="basescore-example-score-addTagButton" class="btn btn-inverse noPrint" style="line-height:10px; padding: 4px 4px;" title="Add tag" onclick="popoverPopup(this, '0', 'tags', 'selectTaxonomy');">+</button>
<div id="basescore-example-customtag-container" style="float:left" data-original-title="" title="">
<button id="basescore-example-score-addTagButton" class="btn btn-inverse noPrint" style="line-height:10px; padding: 4px 4px;" title="Add tag" onclick="addTagWithValue(this);">+</button>
</div>
</div>
</td>
@ -132,12 +132,51 @@ echo $this->element('genericElements/assetLoader', array(
<script>
var taxonomies_with_num_value = <?php echo json_encode($taxonomies); ?>;
var mapping_tag_name_to_tag = {};
var base_score_computation = [];
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function addTagWithValue(clicked) {
var $select = regenerateValidTags();
var html = '<div>' + $select[0].outerHTML + '<button class="btn btn-primary" style="margin-left: 5px;" onclick="addPickedTags(this)"><?php echo __('Tag'); ?></button> </div>';
openPopover(clicked, html, false, 'right', function($popover) {
$popover.find('select').chosen({
width: '300px',
});
});
}
function addPickedTags(clicked) {
$select = $('#basescore-example-tag-picker');
$select.val().forEach(function(tag_id) {
var tag = mapping_tag_name_to_tag[tag_id];
var tag_html = '<div style="display: inline-block;"><span class="tagFirstHalf" style="background-color: ' + tag.colour + '; color: ' + getTextColour(tag.colour) + ';">' + tag.name + '</span>'
+ '<span class="tagSecondHalf useCursorPointer" onclick="$(this).add($(this).prev()).remove()">×</span></div>&nbsp;'
$('#basescore-example-customtag-container').append(tag_html);
});
$('#basescore-example-score-addTagButton').popover('destroy');
}
function regenerateValidTags() {
var $select = $('<select id="basescore-example-tag-picker" multiple="multiple"/>');
Object.keys(taxonomies_with_num_value).forEach(function(taxonomy_name) {
var taxonomy = taxonomies_with_num_value[taxonomy_name];
var $optgroup = $('<optgroup label="' + taxonomy_name + '"></optgroup>');
taxonomy['TaxonomyPredicate'].forEach(function(predicate) {
predicate['TaxonomyEntry'].forEach(function(entry) {
mapping_tag_name_to_tag[entry['Tag']['id']] = entry['Tag'];
var $option = $('<option value="' + entry['Tag']['id'] + '">' + entry['Tag']['name'] + ' [' + entry['Tag']['numerical_value'] + ']</option>');
$optgroup.append($option);
});
});
$select.append($optgroup);
});
return $select;
}
function applyBaseScoreConfig() {
decayingTool.apply_base_score(getRatioScore());
$('#popover_form_large').fadeOut();

View File

@ -1499,7 +1499,7 @@ function openPopup(id, adjust_layout) {
$(id).fadeIn();
}
function openPopover(clicked, data, hover, placement) {
function openPopover(clicked, data, hover, placement, callback) {
hover = hover === undefined ? false : hover;
placement = placement === undefined ? 'right' : placement;
/* popup handling */
@ -1534,6 +1534,9 @@ function openPopover(clicked, data, hover, placement) {
}
var popoverTitle = popover.find('h3.popover-title');
popoverTitle.html(title + closeButtonHtml);
if (callback !== undefined) {
callback(popover);
}
})
.on('keydown.volatilePopover', function(e) {
if(e.keyCode == 27) { // ESC
@ -4198,7 +4201,7 @@ function checkIfLoggedIn() {
window.location.replace(baseurl + "/users/login");
}
}).fail(function() {
window.location.replace(baseurl + "/users/login");
window.location.replace(baseurl + "/users/login");
});
}
setTimeout(function() { checkIfLoggedIn(); }, 5000);