2016-02-22 07:20:34 -06:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import config from 'app/core/config';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import $ from 'jquery';
|
|
|
|
import coreModule from 'app/core/core_module';
|
2016-02-22 08:15:01 -06:00
|
|
|
import Drop from 'tether-drop';
|
2016-02-22 07:20:34 -06:00
|
|
|
|
|
|
|
/** @ngInject **/
|
2017-04-14 04:41:02 -05:00
|
|
|
function popoverSrv($compile, $rootScope, $timeout) {
|
|
|
|
let openDrop = null;
|
|
|
|
|
|
|
|
this.close = function() {
|
|
|
|
if (openDrop) {
|
|
|
|
openDrop.close();
|
|
|
|
}
|
|
|
|
};
|
2016-02-22 07:20:34 -06:00
|
|
|
|
|
|
|
this.show = function(options) {
|
2017-04-14 04:41:02 -05:00
|
|
|
if (openDrop) {
|
|
|
|
openDrop.close();
|
2017-04-14 05:23:32 -05:00
|
|
|
openDrop = null;
|
2017-04-14 04:41:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var scope = _.extend($rootScope.$new(true), options.model);
|
2016-02-22 11:46:58 -06:00
|
|
|
var drop;
|
|
|
|
|
2017-04-14 04:41:02 -05:00
|
|
|
var cleanUp = () => {
|
|
|
|
setTimeout(() => {
|
|
|
|
scope.$destroy();
|
2017-04-14 05:23:32 -05:00
|
|
|
|
|
|
|
if (drop.tether) {
|
|
|
|
drop.destroy();
|
|
|
|
}
|
2017-04-13 11:39:49 -05:00
|
|
|
|
2017-04-14 04:41:02 -05:00
|
|
|
if (options.onClose) {
|
|
|
|
options.onClose();
|
2016-02-22 11:46:58 -06:00
|
|
|
}
|
|
|
|
});
|
2017-04-14 05:23:32 -05:00
|
|
|
|
|
|
|
openDrop = null;
|
2017-04-14 04:41:02 -05:00
|
|
|
};
|
2016-02-22 11:46:58 -06:00
|
|
|
|
2017-04-14 04:41:02 -05:00
|
|
|
scope.dismiss = () => {
|
|
|
|
drop.close();
|
2016-02-22 11:46:58 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
var contentElement = document.createElement('div');
|
|
|
|
contentElement.innerHTML = options.template;
|
2016-02-22 07:20:34 -06:00
|
|
|
|
2017-04-14 04:41:02 -05:00
|
|
|
$compile(contentElement)(scope);
|
2016-02-22 11:46:58 -06:00
|
|
|
|
2017-04-14 05:23:32 -05:00
|
|
|
$timeout(() => {
|
|
|
|
drop = new Drop({
|
|
|
|
target: options.element,
|
|
|
|
content: contentElement,
|
|
|
|
position: options.position,
|
|
|
|
classes: options.classNames || 'drop-popover',
|
|
|
|
openOn: options.openOn,
|
|
|
|
hoverCloseDelay: 200,
|
|
|
|
tetherOptions: {
|
|
|
|
constraints: [{to: 'scrollParent', attachment: "none both"}]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
drop.on('close', () => {
|
|
|
|
cleanUp();
|
|
|
|
});
|
|
|
|
|
|
|
|
openDrop = drop;
|
|
|
|
openDrop.open();
|
|
|
|
}, 10);
|
2016-02-22 07:20:34 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
coreModule.service('popoverSrv', popoverSrv);
|