Merge "eslint cleanup of draggable-components.js"
This commit is contained in:
commit
dbc8089f51
|
@ -12,6 +12,9 @@ globals:
|
||||||
# allow accessing horizon
|
# allow accessing horizon
|
||||||
horizon: false
|
horizon: false
|
||||||
|
|
||||||
|
# allow passing TENANT_ID from django templates
|
||||||
|
TENANT_ID: false
|
||||||
|
|
||||||
# Only support ECMA5, disable everything else.
|
# Only support ECMA5, disable everything else.
|
||||||
# NOTE(kzaitsev): blatantly copied from horizon
|
# NOTE(kzaitsev): blatantly copied from horizon
|
||||||
ecmaFeatures:
|
ecmaFeatures:
|
||||||
|
|
|
@ -1,10 +1,27 @@
|
||||||
|
/* Copyright (c) 2013 Mirantis, Inc.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
not use this file except in compliance with the License. You may obtain
|
||||||
|
a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
License for the specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
*/
|
||||||
$(function() {
|
$(function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
horizon.tabs.addTabLoadFunction(initServicesTab);
|
horizon.tabs.addTabLoadFunction(initServicesTab);
|
||||||
initServicesTab($('.tab-content .tab-pane.active'));
|
initServicesTab($('.tab-content .tab-pane.active'));
|
||||||
|
|
||||||
function initServicesTab($tab) {
|
function initServicesTab($tab) {
|
||||||
var $dropArea = $tab.find('.drop_component'),
|
var $dropArea = $tab.find('.drop_component');
|
||||||
draggedAppUrl = null,
|
var draggedAppUrl = null;
|
||||||
firstDropTarget = null;
|
var firstDropTarget = null;
|
||||||
|
|
||||||
function bindAppTileHandlers() {
|
function bindAppTileHandlers() {
|
||||||
$('.draggable_app').each(function () {
|
$('.draggable_app').each(function () {
|
||||||
|
@ -17,7 +34,7 @@ $(function() {
|
||||||
ev.originalEvent.dataTransfer.setData('text/uri-list', draggedAppUrl);
|
ev.originalEvent.dataTransfer.setData('text/uri-list', draggedAppUrl);
|
||||||
}).on('dragend', function () {
|
}).on('dragend', function () {
|
||||||
$dropArea.removeClass('over');
|
$dropArea.removeClass('over');
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +55,11 @@ $(function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
var packages = $.parseJSON($('#apps_carousel_contents').val());
|
var packages = $.parseJSON($('#apps_carousel_contents').val());
|
||||||
function subdivide(numOfItems) {
|
function subdivide(array, numOfItems) {
|
||||||
var chunks = [],
|
var chunks = [];
|
||||||
seq = this,
|
var seq = array;
|
||||||
head = seq.slice(0, numOfItems),
|
var head = seq.slice(0, numOfItems);
|
||||||
tail = seq.slice(numOfItems);
|
var tail = seq.slice(numOfItems);
|
||||||
while (tail.length) {
|
while (tail.length) {
|
||||||
chunks.push(head);
|
chunks.push(head);
|
||||||
head = tail.slice(0, numOfItems);
|
head = tail.slice(0, numOfItems);
|
||||||
|
@ -52,21 +69,29 @@ $(function() {
|
||||||
return chunks;
|
return chunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.prototype.subdivide = subdivide;
|
var $carouselInner = $tab.find('.carousel-inner');
|
||||||
var $carouselInner = $tab.find('.carousel-inner'),
|
var $carousel = $('#apps_carousel');
|
||||||
$carousel = $('#apps_carousel'),
|
var $filter = $('#envAppsFilter').find('input');
|
||||||
$filter = $('#envAppsFilter').find('input'),
|
var $noAppMsg = $('#no_apps_found_message');
|
||||||
$noAppMsg = $('#no_apps_found_message'),
|
var category = 'All';
|
||||||
category = ALL_CATEGORY = 'All',
|
var ALL_CATEGORY = 'All';
|
||||||
filterValue = '',
|
var filterValue = '';
|
||||||
ENTER_KEYCODE = 13;
|
var ENTER_KEYCODE = 13;
|
||||||
var tileTemplate = Hogan.compile($('#app_tile_small').html()),
|
var tileTemplate,
|
||||||
|
environmentId;
|
||||||
|
|
||||||
|
var $appTitleSmall = $('#app_tile_small');
|
||||||
|
if ($appTitleSmall.length > 0) {
|
||||||
|
tileTemplate = Hogan.compile($appTitleSmall.html());
|
||||||
|
}
|
||||||
|
if ($('#environmentId').length > 0) {
|
||||||
environmentId = $('#environmentId').val();
|
environmentId = $('#environmentId').val();
|
||||||
|
}
|
||||||
|
|
||||||
function fillCarousel(apps) {
|
function fillCarousel(apps) {
|
||||||
var i = apps.length;
|
var i = apps.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
if (tenant_id !== apps[i].owner_id && apps[i].is_public == false) {
|
if (TENANT_ID !== apps[i].owner_id && apps[i].is_public === false) {
|
||||||
apps.splice(i, 1);
|
apps.splice(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,10 +101,10 @@ $(function() {
|
||||||
if ($carousel.css('display') === 'none') {
|
if ($carousel.css('display') === 'none') {
|
||||||
$carousel.show();
|
$carousel.show();
|
||||||
}
|
}
|
||||||
apps.subdivide(6).forEach(function (chunk, index) {
|
subdivide(apps, 6).forEach(function (chunk, index) {
|
||||||
var $item = $('<div class="item"></div>'),
|
var $item = $('<div class="item"></div>');
|
||||||
$row = $('<div class="row"></div>');
|
var $row = $('<div class="row"></div>');
|
||||||
if (index == 0) {
|
if (index === 0) {
|
||||||
$item.addClass('active');
|
$item.addClass('active');
|
||||||
}
|
}
|
||||||
$item.appendTo($row);
|
$item.appendTo($row);
|
||||||
|
@ -90,14 +115,14 @@ $(function() {
|
||||||
app_id: pkg.id
|
app_id: pkg.id
|
||||||
});
|
});
|
||||||
// tenant_id is obtained from corresponding Django template
|
// tenant_id is obtained from corresponding Django template
|
||||||
if (tenant_id === pkg.owner_id) {
|
if (TENANT_ID === pkg.owner_id) {
|
||||||
html = $(html).find('img.ribbon').remove().end();
|
html = $(html).find('img.ribbon').remove().end();
|
||||||
}
|
}
|
||||||
$(html).appendTo($item);
|
$(html).appendTo($item);
|
||||||
});
|
});
|
||||||
$item.appendTo($carouselInner);
|
$item.appendTo($carouselInner);
|
||||||
});
|
});
|
||||||
$('div.carousel-control').removeClass('item')
|
$('div.carousel-control').removeClass('item');
|
||||||
bindAppTileHandlers();
|
bindAppTileHandlers();
|
||||||
} else {
|
} else {
|
||||||
if ($('#no_apps_in_catalog_message').length == 0) {
|
if ($('#no_apps_in_catalog_message').length == 0) {
|
||||||
|
@ -118,10 +143,11 @@ $(function() {
|
||||||
if (category === ALL_CATEGORY && filterValue === '') {
|
if (category === ALL_CATEGORY && filterValue === '') {
|
||||||
fillCarousel(packages);
|
fillCarousel(packages);
|
||||||
} else {
|
} else {
|
||||||
var filterRegexp = new RegExp(filterValue, 'i'),
|
var filterRegexp = new RegExp(filterValue, 'i');
|
||||||
filterRegexpExact = new RegExp('\\b' + filterValue + '\\b', 'i');
|
var filterRegexpExact = new RegExp('\\b' + filterValue + '\\b', 'i');
|
||||||
fillCarousel(packages.filter(function (pkg) {
|
fillCarousel(packages.filter(function (pkg) {
|
||||||
var categorySatisfied = true, filterSatisfied = true;
|
var categorySatisfied = true;
|
||||||
|
var filterSatisfied = true;
|
||||||
if (category !== ALL_CATEGORY) {
|
if (category !== ALL_CATEGORY) {
|
||||||
categorySatisfied = pkg.categories.indexOf(category) > -1;
|
categorySatisfied = pkg.categories.indexOf(category) > -1;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +159,7 @@ $(function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return categorySatisfied && filterSatisfied;
|
return categorySatisfied && filterSatisfied;
|
||||||
}))
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +172,7 @@ $(function() {
|
||||||
});
|
});
|
||||||
// dynamic carousel refilling on search box non-empty submission
|
// dynamic carousel refilling on search box non-empty submission
|
||||||
$filter.keypress(function (ev) {
|
$filter.keypress(function (ev) {
|
||||||
if (ev.which == ENTER_KEYCODE) {
|
if (ev.which === ENTER_KEYCODE) {
|
||||||
filterValue = $filter.val();
|
filterValue = $filter.val();
|
||||||
refillCarousel();
|
refillCarousel();
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
@ -170,7 +196,7 @@ $(function() {
|
||||||
|
|
||||||
function handleError() {
|
function handleError() {
|
||||||
hideSpinner();
|
hideSpinner();
|
||||||
horizon.alert('error', 'Unable to run action.');
|
horizon.alert('error', gettext('Unable to run action.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
bindActionHandlers($tab);
|
bindActionHandlers($tab);
|
||||||
|
@ -181,19 +207,37 @@ $(function() {
|
||||||
|
|
||||||
function bindActionHandlers($parent) {
|
function bindActionHandlers($parent) {
|
||||||
$parent.find('.murano_action').off('click').on('click', function(event) {
|
$parent.find('.murano_action').off('click').on('click', function(event) {
|
||||||
var $this = $(this),
|
var $this = $(this);
|
||||||
$form = $this.closest('.table_wrapper > form'),
|
var $form = $this.closest('.table_wrapper > form');
|
||||||
startUrl = $this.attr('href'),
|
var startUrl = $this.attr('href');
|
||||||
resultUrl = null,
|
var resultUrl = null;
|
||||||
ERRDATA = 'error',
|
var ERRDATA = 'error';
|
||||||
data = null;
|
var data = null;
|
||||||
|
function doRequest(url) {
|
||||||
|
var requestData;
|
||||||
|
$.ajax({
|
||||||
|
method: 'GET',
|
||||||
|
url: url,
|
||||||
|
async: false,
|
||||||
|
error: function () {
|
||||||
|
handleError();
|
||||||
|
requestData = ERRDATA;
|
||||||
|
},
|
||||||
|
success: function (newData) {
|
||||||
|
requestData = newData;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return requestData;
|
||||||
|
}
|
||||||
|
|
||||||
horizon.modals.modal_spinner(gettext("Waiting for a result"));
|
horizon.modals.modal_spinner(gettext("Waiting for a result"));
|
||||||
button = '<div class="modal-close"' +
|
var button = '<div class="modal-close"' +
|
||||||
'><button class="btn btn-sm btn-danger" data-placement="right"' +
|
'><button class="btn btn-sm btn-danger" data-placement="right"' +
|
||||||
' data-original-title="Action result won\'t be available">Stop Waiting</button></div>'
|
' data-original-title="Action result won\'t be available">Stop Waiting</button></div>';
|
||||||
var modal_content = horizon.modals.spinner.find(".modal-content");
|
var modalContent = horizon.modals.spinner.find(".modal-content");
|
||||||
modal_content.append(button);
|
var intervalId;
|
||||||
|
|
||||||
|
modalContent.append(button);
|
||||||
$('.modal-close button').tooltip();
|
$('.modal-close button').tooltip();
|
||||||
$('.modal-close button').on("click", function () {
|
$('.modal-close button').on("click", function () {
|
||||||
window.clearInterval(intervalId);
|
window.clearInterval(intervalId);
|
||||||
|
@ -205,30 +249,14 @@ $(function() {
|
||||||
url: startUrl,
|
url: startUrl,
|
||||||
data: $form.serialize(),
|
data: $form.serialize(),
|
||||||
async: false,
|
async: false,
|
||||||
success: function (data) {
|
success: function (successData) {
|
||||||
resultUrl = data && data.url;
|
resultUrl = successData && successData.url;
|
||||||
},
|
},
|
||||||
error: handleError
|
error: handleError
|
||||||
});
|
});
|
||||||
if ( resultUrl ) {
|
if ( resultUrl ) {
|
||||||
function doRequest(url) {
|
|
||||||
var _data;
|
|
||||||
$.ajax({
|
|
||||||
method: 'GET',
|
|
||||||
url: url,
|
|
||||||
async: false,
|
|
||||||
error: function () {
|
|
||||||
handleError();
|
|
||||||
_data = ERRDATA;
|
|
||||||
},
|
|
||||||
success: function (newData) {
|
|
||||||
_data = newData;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return _data;
|
|
||||||
}
|
|
||||||
|
|
||||||
var intervalId = window.setInterval(function () {
|
intervalId = window.setInterval(function () {
|
||||||
// it's better to avoid placing the whole downloadable content
|
// it's better to avoid placing the whole downloadable content
|
||||||
// into JS memory in case of downloading very large files
|
// into JS memory in case of downloading very large files
|
||||||
data = doRequest(resultUrl + 'poll');
|
data = doRequest(resultUrl + 'poll');
|
||||||
|
@ -255,7 +283,5 @@ $(function() {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -49,6 +49,6 @@
|
||||||
<script src="{% static 'muranodashboard/js/draggable-components.js' %}"></script>
|
<script src="{% static 'muranodashboard/js/draggable-components.js' %}"></script>
|
||||||
<script src="{% static 'muranodashboard/js/horizon.tables+reload.js' %}"></script>
|
<script src="{% static 'muranodashboard/js/horizon.tables+reload.js' %}"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var tenant_id = "{{tenant_id}}"
|
var TENANT_ID = "{{tenant_id}}";
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue