Private GIT

Skip to content
Snippets Groups Projects
Commit 7b5d86f2 authored by Ridene's avatar Ridene Committed by Ridene
Browse files

feat(popin) : improve popin to modal

Add possiblitiy to change centreon popin
to a modal

Refs: #5607
parent 0515efa0
No related branches found
No related tags found
No related merge requests found
...@@ -36,9 +36,11 @@ ...@@ -36,9 +36,11 @@
'use strict'; 'use strict';
function CentreonPopin(settings, $elem) { function CentreonPopin(settings, $elem) {
var self = this; var self = this,
var closeBtn = $('<a class="close" href="#"><img src="./img/icons/circle-cross.png" class="ico-18"></a>'); closeBtn = $('<a class="close" href="#">' +
var $newElem = $('<div></div>'); '<img src="./img/icons/circle-cross.png" class="ico-18"></a>'),
$newElem = $('<div></div>');
self.settings = settings; self.settings = settings;
/* Add class */ /* Add class */
...@@ -46,7 +48,6 @@ ...@@ -46,7 +48,6 @@
$newElem.addClass('centreon-popin'); $newElem.addClass('centreon-popin');
$newElem.hide(); $newElem.hide();
$elem.wrap($newElem); $elem.wrap($newElem);
self.$elem = $elem.parents('.centreon-popin').detach(); self.$elem = $elem.parents('.centreon-popin').detach();
self.$elem.appendTo('body'); self.$elem.appendTo('body');
...@@ -101,18 +102,25 @@ ...@@ -101,18 +102,25 @@
.addClass('centreon-popin-overlay') .addClass('centreon-popin-overlay')
.hide() .hide()
.prependTo('body'); .prependTo('body');
if (self.settings.isModal) {
$('.close').hide();
$('.centreon-popin').css({'padding': '1em'})
} }
}
},
handleOverlay: function() {
var self = this;
$('#centreonPopinOverlay').on('click', function (e) { $('#centreonPopinOverlay').on('click', function (e) {
if (self.settings.closeOnDocument) { if (!self.settings.isModal) {
if ($(e.target).parents('.centreon-popin').length === 0) { if ($(e.target).parents('.centreon-popin').length === 0) {
self.close(); self.close();
} }
} }
}); });
}, },
setUrl : function(url){
this.settings.url = url;
},
reset: function() { reset: function() {
var self = this; var self = this;
...@@ -159,6 +167,8 @@ ...@@ -159,6 +167,8 @@
this.setCenter(); this.setCenter();
this.setScroll(); this.setScroll();
this.opened = true; this.opened = true;
this.handleOverlay();
}, },
close: function () { close: function () {
this.opened = false; this.opened = false;
...@@ -168,7 +178,7 @@ ...@@ -168,7 +178,7 @@
} else { } else {
this.$elem.hide(); this.$elem.hide();
} }
$('#centreonPopinOverlay').hide(); $('#centreonPopinOverlay').hide().off('click');
/* Execute callback if defined on settings */ /* Execute callback if defined on settings */
if (typeof(this.settings.onClose) === 'function') { if (typeof(this.settings.onClose) === 'function') {
...@@ -178,24 +188,29 @@ ...@@ -178,24 +188,29 @@
}; };
$.fn.centreonPopin = function (options) { $.fn.centreonPopin = function (options) {
var args = Array.prototype.splice.call(arguments, 1); var args = Array.prototype.splice.call(arguments, 1),
var settings = $.extend({}, $.fn.centreonPopin.defaults, options); settings = $.extend({}, $.fn.centreonPopin.defaults, options),
var methodReturn; methodReturn;
var $set = this.each(function () { var $set = this.each(function () {
var $this = $(this); var $this = $(this),
var data = $this.data('centreonPopin'); data = $this.data('centreonPopin');
if (!data) { if (!data) {
$this.data('centreonPopin', (data = new CentreonPopin(settings, $this))); $this.data('centreonPopin', (data = new CentreonPopin(settings, $this)));
} }
if (typeof options === 'string') { if (typeof options === 'string') {
methodReturn = data[options].apply(data, args); methodReturn = data[options].apply(data, args);
} else if (options.open) {
methodReturn = data['open'].apply(data, args);
} }
}); });
return (methodReturn === undefined) ? $set : methodReturn; if (methodReturn === undefined) return $set;
}; };
$.fn.centreonPopin.defaults = { $.fn.centreonPopin.defaults = {
closeOnDocument: true, isModal: false,
open: false, open: false,
url : null, url : null,
ajaxDataType: 'html', ajaxDataType: 'html',
......
...@@ -683,9 +683,18 @@ jQuery(function () { ...@@ -683,9 +683,18 @@ jQuery(function () {
jQuery('#formAddView input[name="public"]').prop('checked', false); jQuery('#formAddView input[name="public"]').prop('checked', false);
}); });
jQuery('.setDefault').button({ icons : { primary: 'ui-icon-arrowreturnthick-1-w'}}).on('click', function () {
jQuery("#setDefaultConfirm").centreonPopin({
open: true
});
});
jQuery('.editView').button({ icons : { primary: 'ui-icon-gear'}}); jQuery('.editView').button({ icons : { primary: 'ui-icon-gear'}});
jQuery('.deleteView').button({ icons : { primary: 'ui-icon-trash'}}).on('click', function () { jQuery('.deleteView').button({ icons : { primary: 'ui-icon-trash'}}).on('click', function () {
jQuery("#deleteViewConfirm").centreonPopin("open"); jQuery("#deleteViewConfirm").centreonPopin({
open: true
});
}); });
jQuery('.shareView').button({ icons : { primary: 'ui-icon-folder-open'}}).on('click', function () { jQuery('.shareView').button({ icons : { primary: 'ui-icon-folder-open'}}).on('click', function () {
...@@ -736,9 +745,6 @@ jQuery(function () { ...@@ -736,9 +745,6 @@ jQuery(function () {
}); });
jQuery('.addWidget').button({ icons : { primary: 'ui-icon-plus'}}); jQuery('.addWidget').button({ icons : { primary: 'ui-icon-plus'}});
jQuery('.setRotate').button({ icons : { primary: 'ui-icon-play'}}); jQuery('.setRotate').button({ icons : { primary: 'ui-icon-play'}});
jQuery('.setDefault').button({ icons : { primary: 'ui-icon-arrowreturnthick-1-w'}}).on('click', function () {
jQuery("#setDefaultConfirm").centreonPopin('open');
});
jQuery('input[name="create_load[create_load]"]').change(function (){ jQuery('input[name="create_load[create_load]"]').change(function (){
if (jQuery(this).val() == 'load'){ if (jQuery(this).val() == 'load'){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment