123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- 'use strict';
- var activitiModeler = angular.module('activitiModeler', [
- 'ngCookies',
- 'ngResource',
- 'ngSanitize',
- 'ngRoute',
- 'ngDragDrop',
- 'mgcrea.ngStrap',
- 'ngGrid',
- 'ngAnimate',
- 'pascalprecht.translate',
- 'duScroll',
- 'tm.pagination'
- ]);
- var activitiModule = activitiModeler;
- activitiModeler
- .config(['$selectProvider', '$translateProvider', function ($selectProvider, $translateProvider) {
-
- angular.extend($selectProvider.defaults, {
- caretHtml: ' <i class="icon icon-caret-down"></i>'
- });
-
- $translateProvider.useStaticFilesLoader({
- prefix: './editor-app/i18n/',
- suffix: '.json'
- });
- $translateProvider.preferredLanguage('en');
-
- $translateProvider.useCookieStorage();
- }])
- .run(['$rootScope', '$timeout', '$modal', '$translate', '$location', '$window', '$http', '$q',
- function ($rootScope, $timeout, $modal, $translate, $location, $window, $http, $q) {
- $rootScope.config = ACTIVITI.CONFIG;
- $rootScope.editorInitialized = false;
- $rootScope.editorFactory = $q.defer();
- $rootScope.forceSelectionRefresh = false;
- $rootScope.ignoreChanges = false;
- $rootScope.validationErrors = [];
- $rootScope.staticIncludeVersion = Date.now();
-
- $rootScope.safeApply = function (fn) {
- var phase = this.$root.$$phase;
- if (phase == '$apply' || phase == '$digest') {
- if (fn && (typeof(fn) === 'function')) {
- fn();
- }
- } else {
- this.$apply(fn);
- }
- };
-
-
- function fetchModel(modelId) {
- var modelUrl = KISBPM.URL.getModel(modelId);
- $http({method: 'GET', url: modelUrl}).success(function (data, status, headers, config) {
- $rootScope.editor = new ORYX.Editor(data);
- $rootScope.modelData = angular.fromJson(data);
- $rootScope.editorFactory.resolve();
- }).error(function (data, status, headers, config) {
- console.log('Error loading model with id ' + modelId + ' ' + data);
- });
- }
- function initScrollHandling() {
- var canvasSection = jQuery('#canvasSection');
- canvasSection.scroll(function () {
-
- var selectedElements = $rootScope.editor.selection;
- var subSelectionElements = $rootScope.editor._subSelection;
- $rootScope.selectedElements = selectedElements;
- $rootScope.subSelectionElements = subSelectionElements;
- if (selectedElements && selectedElements.length > 0) {
- $rootScope.selectedElementBeforeScrolling = selectedElements[0];
- }
- jQuery('.Oryx_button').each(function (i, obj) {
- $rootScope.orginalOryxButtonStyle = obj.style.display;
- obj.style.display = 'none';
- });
- jQuery('.resizer_southeast').each(function (i, obj) {
- $rootScope.orginalResizerSEStyle = obj.style.display;
- obj.style.display = 'none';
- });
- jQuery('.resizer_northwest').each(function (i, obj) {
- $rootScope.orginalResizerNWStyle = obj.style.display;
- obj.style.display = 'none';
- });
- $rootScope.editor.handleEvents({type: ORYX.CONFIG.EVENT_CANVAS_SCROLL});
- });
- canvasSection.scrollStopped(function () {
-
- $rootScope.editor.setSelection([]);
- $rootScope.editor.setSelection($rootScope.selectedElements, $rootScope.subSelectionElements);
- $rootScope.selectedElements = undefined;
- $rootScope.subSelectionElements = undefined;
- function handleDisplayProperty(obj) {
- if (jQuery(obj).position().top > 0) {
- obj.style.display = 'block';
- } else {
- obj.style.display = 'none';
- }
- }
- jQuery('.Oryx_button').each(function (i, obj) {
- handleDisplayProperty(obj);
- });
- jQuery('.resizer_southeast').each(function (i, obj) {
- handleDisplayProperty(obj);
- });
- jQuery('.resizer_northwest').each(function (i, obj) {
- handleDisplayProperty(obj);
- });
- });
- }
-
- $rootScope.$on('$includeContentLoaded', function (event) {
- if (!$rootScope.editorInitialized) {
- ORYX._loadPlugins();
- var modelId = EDITOR.UTIL.getParameterByName('modelId');
- fetchModel(modelId);
- $rootScope.window = {};
- var updateWindowSize = function () {
- $rootScope.window.width = $window.innerWidth;
- $rootScope.window.height = $window.innerHeight;
- };
-
- angular.element($window).bind('resize', function () {
- $rootScope.safeApply(updateWindowSize());
- });
- $rootScope.$watch('window.forceRefresh', function (newValue) {
- if (newValue) {
- $timeout(function () {
- updateWindowSize();
- $rootScope.window.forceRefresh = false;
- });
- }
- });
- updateWindowSize();
-
-
- jQuery(window).resize(function () {
-
- var offset = jQuery("#editor-header").offset();
- var propSectionHeight = jQuery('#propertySection').height();
- var canvas = jQuery('#canvasSection');
- var mainHeader = jQuery('#main-header');
- if (offset == undefined || offset === null
- || propSectionHeight === undefined || propSectionHeight === null
- || canvas === undefined || canvas === null || mainHeader === null) {
- return;
- }
- if ($rootScope.editor) {
- var selectedElements = $rootScope.editor.selection;
- var subSelectionElements = $rootScope.editor._subSelection;
- $rootScope.selectedElements = selectedElements;
- $rootScope.subSelectionElements = subSelectionElements;
- if (selectedElements && selectedElements.length > 0) {
- $rootScope.selectedElementBeforeScrolling = selectedElements[0];
- $rootScope.editor.setSelection([]);
- $rootScope.editor.setSelection($rootScope.selectedElements, $rootScope.subSelectionElements);
- $rootScope.selectedElements = undefined;
- $rootScope.subSelectionElements = undefined;
- }
- }
- var totalAvailable = jQuery(window).height() - offset.top - mainHeader.height() - 50;
- canvas.height(totalAvailable - propSectionHeight);
- jQuery('#paletteSection').height(totalAvailable);
-
- var actualCanvas = null;
- if (canvas && canvas[0].children[1]) {
- actualCanvas = canvas[0].children[1];
- }
- var canvasTop = canvas.position().top;
- var canvasLeft = canvas.position().left;
- var canvasHeight = canvas[0].clientHeight;
- var canvasWidth = canvas[0].clientWidth;
- var iconCenterOffset = 8;
- var widthDiff = 0;
- var actualWidth = 0;
- if (actualCanvas) {
-
- actualWidth = actualCanvas.clientWidth || actualCanvas.parentNode.clientWidth;
- }
- if (actualWidth < canvas[0].clientWidth) {
- widthDiff = actualWidth - canvas[0].clientWidth;
-
- canvasLeft -= widthDiff / 2;
- canvasWidth += widthDiff;
- }
- var iconWidth = 17;
- var iconOffset = 20;
- var north = jQuery('#canvas-grow-N');
- north.css('top', canvasTop + iconOffset + 'px');
- north.css('left', canvasLeft - 10 + (canvasWidth - iconWidth) / 2 + 'px');
- var south = jQuery('#canvas-grow-S');
- south.css('top', (canvasTop + canvasHeight - iconOffset - iconCenterOffset) + 'px');
- south.css('left', canvasLeft - 10 + (canvasWidth - iconWidth) / 2 + 'px');
- var east = jQuery('#canvas-grow-E');
- east.css('top', canvasTop - 10 + (canvasHeight - iconWidth) / 2 + 'px');
- east.css('left', (canvasLeft + canvasWidth - iconOffset - iconCenterOffset) + 'px');
- var west = jQuery('#canvas-grow-W');
- west.css('top', canvasTop - 10 + (canvasHeight - iconWidth) / 2 + 'px');
- west.css('left', canvasLeft + iconOffset + 'px');
- north = jQuery('#canvas-shrink-N');
- north.css('top', canvasTop + iconOffset + 'px');
- north.css('left', canvasLeft + 10 + (canvasWidth - iconWidth) / 2 + 'px');
- south = jQuery('#canvas-shrink-S');
- south.css('top', (canvasTop + canvasHeight - iconOffset - iconCenterOffset) + 'px');
- south.css('left', canvasLeft + 10 + (canvasWidth - iconWidth) / 2 + 'px');
- east = jQuery('#canvas-shrink-E');
- east.css('top', canvasTop + 10 + (canvasHeight - iconWidth) / 2 + 'px');
- east.css('left', (canvasLeft + canvasWidth - iconOffset - iconCenterOffset) + 'px');
- west = jQuery('#canvas-shrink-W');
- west.css('top', canvasTop + 10 + (canvasHeight - iconWidth) / 2 + 'px');
- west.css('left', canvasLeft + iconOffset + 'px');
- });
- jQuery(window).trigger('resize');
- jQuery.fn.scrollStopped = function (callback) {
- jQuery(this).scroll(function () {
- var self = this, $this = jQuery(self);
- if ($this.data('scrollTimeout')) {
- clearTimeout($this.data('scrollTimeout'));
- }
- $this.data('scrollTimeout', setTimeout(callback, 50, self));
- });
- };
-
- initScrollHandling();
- $rootScope.editorInitialized = true;
- }
- });
-
- $rootScope.editorFactory.promise.then(function () {
- KISBPM.eventBus.editor = $rootScope.editor;
- var eventMappings = [
- {
- oryxType: ORYX.CONFIG.EVENT_SELECTION_CHANGED,
- kisBpmType: KISBPM.eventBus.EVENT_TYPE_SELECTION_CHANGE
- },
- {oryxType: ORYX.CONFIG.EVENT_DBLCLICK, kisBpmType: KISBPM.eventBus.EVENT_TYPE_DOUBLE_CLICK},
- {oryxType: ORYX.CONFIG.EVENT_MOUSEOUT, kisBpmType: KISBPM.eventBus.EVENT_TYPE_MOUSE_OUT},
- {oryxType: ORYX.CONFIG.EVENT_MOUSEOVER, kisBpmType: KISBPM.eventBus.EVENT_TYPE_MOUSE_OVER}
- ];
- eventMappings.forEach(function (eventMapping) {
- $rootScope.editor.registerOnEvent(eventMapping.oryxType, function (event) {
- KISBPM.eventBus.dispatch(eventMapping.kisBpmType, event);
- });
- });
- $rootScope.editor.registerOnEvent(ORYX.CONFIG.EVENT_SHAPEREMOVED, function (event) {
- var validateButton = document.getElementById(event.shape.resourceId + "-validate-button");
- if (validateButton) {
- validateButton.style.display = 'none';
- }
- });
-
-
- KISBPM.eventBus.dispatch(KISBPM.eventBus.EVENT_TYPE_EDITOR_READY, {type: KISBPM.eventBus.EVENT_TYPE_EDITOR_READY});
- });
-
- $rootScope.alerts = {
- queue: []
- };
- $rootScope.showAlert = function (alert) {
- if (alert.queue.length > 0) {
- alert.current = alert.queue.shift();
-
- alert.timeout = $timeout(function () {
- if (alert.queue.length == 0) {
- alert.current = undefined;
- alert.timeout = undefined;
- } else {
- $rootScope.showAlert(alert);
- }
- }, (alert.current.type == 'error' ? 5000 : 1000));
- } else {
- $rootScope.alerts.current = undefined;
- }
- };
- $rootScope.addAlert = function (message, type) {
- var newAlert = {message: message, type: type};
- if (!$rootScope.alerts.timeout) {
-
- $rootScope.alerts.queue.push(newAlert);
- $rootScope.showAlert($rootScope.alerts);
- } else {
- $rootScope.alerts.queue.push(newAlert);
- }
- };
- $rootScope.dismissAlert = function () {
- if (!$rootScope.alerts.timeout) {
- $rootScope.alerts.current = undefined;
- } else {
- $timeout.cancel($rootScope.alerts.timeout);
- $rootScope.alerts.timeout = undefined;
- $rootScope.showAlert($rootScope.alerts);
- }
- };
- $rootScope.addAlertPromise = function (promise, type) {
- if (promise) {
- promise.then(function (data) {
- $rootScope.addAlert(data, type);
- });
- }
- };
- }
- ])
-
- .filter('dateformat', function () {
- return function (date, format) {
- if (date) {
- if (format) {
- return moment(date).format(format);
- } else {
- return moment(date).calendar();
- }
- }
- return '';
- };
- });
|