Merge branch 'master' of https://github.com/nasa/openmctweb into search
Conflicts: platform/commonUI/general/src/controllers/TreeNodeController.js platform/persistence/elastic/src/ElasticSearchProvider.js
This commit is contained in:
@@ -21,6 +21,11 @@
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements Open MCT Web's About dialog.
|
||||
* @namespace platform/commonUI/about
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
@@ -29,35 +34,36 @@ define(
|
||||
/**
|
||||
* The AboutController provides information to populate the
|
||||
* About dialog.
|
||||
* @memberof platform/commonUI/about
|
||||
* @constructor
|
||||
* @param {object[]} versions an array of version extensions;
|
||||
* injected from `versions[]`
|
||||
* @param $window Angular-injected window object
|
||||
*/
|
||||
function AboutController(versions, $window) {
|
||||
return {
|
||||
/**
|
||||
* Get version info. This is given as an array of
|
||||
* objects, where each object is intended to appear
|
||||
* as a line-item in the version information listing.
|
||||
* @memberof AboutController#
|
||||
* @returns {object[]} version information
|
||||
*/
|
||||
versions: function () {
|
||||
return versions;
|
||||
},
|
||||
/**
|
||||
* Open a new window (or tab, depending on browser
|
||||
* configuration) containing open source licenses.
|
||||
* @memberof AboutController#
|
||||
*/
|
||||
openLicenses: function () {
|
||||
// Open a new browser window at the licenses route
|
||||
$window.open("#/licenses");
|
||||
}
|
||||
};
|
||||
this.versionDefinitions = versions;
|
||||
this.$window = $window;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get version info. This is given as an array of
|
||||
* objects, where each object is intended to appear
|
||||
* as a line-item in the version information listing.
|
||||
* @returns {object[]} version information
|
||||
*/
|
||||
AboutController.prototype.versions = function () {
|
||||
return this.versionDefinitions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Open a new window (or tab, depending on browser
|
||||
* configuration) containing open source licenses.
|
||||
*/
|
||||
AboutController.prototype.openLicenses = function () {
|
||||
// Open a new browser window at the licenses route
|
||||
this.$window.open("#/licenses");
|
||||
};
|
||||
|
||||
return AboutController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -29,20 +29,22 @@ define(
|
||||
/**
|
||||
* Provides extension-introduced licenses information to the
|
||||
* licenses route.
|
||||
* @memberof platform/commonUI/about
|
||||
* @constructor
|
||||
*/
|
||||
function LicenseController(licenses) {
|
||||
return {
|
||||
/**
|
||||
* Get license information.
|
||||
* @returns {Array} license extensions
|
||||
*/
|
||||
licenses: function () {
|
||||
return licenses;
|
||||
}
|
||||
};
|
||||
this.licenseDefinitions = licenses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get license information.
|
||||
* @returns {Array} license extensions
|
||||
* @memberof platform/commonUI/about.LicenseController#
|
||||
*/
|
||||
LicenseController.prototype.licenses = function () {
|
||||
return this.licenseDefinitions;
|
||||
};
|
||||
|
||||
return LicenseController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -29,21 +29,23 @@ define(
|
||||
/**
|
||||
* The LogoController provides functionality to the application
|
||||
* logo in the bottom-right of the user interface.
|
||||
* @memberof platform/commonUI/about
|
||||
* @constructor
|
||||
* @param {OverlayService} overlayService the overlay service
|
||||
*/
|
||||
function LogoController(overlayService) {
|
||||
return {
|
||||
/**
|
||||
* Display the About dialog.
|
||||
* @memberof LogoController#
|
||||
*/
|
||||
showAboutDialog: function () {
|
||||
overlayService.createOverlay("overlay-about");
|
||||
}
|
||||
};
|
||||
this.overlayService = overlayService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the About dialog.
|
||||
* @memberof LogoController#
|
||||
* @memberof platform/commonUI/about.LogoController#
|
||||
*/
|
||||
LogoController.prototype.showAboutDialog = function () {
|
||||
this.overlayService.createOverlay("overlay-about");
|
||||
};
|
||||
|
||||
return LogoController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -69,8 +69,8 @@
|
||||
{
|
||||
"key": "grid-item",
|
||||
"templateUrl": "templates/items/grid-item.html",
|
||||
"uses": [ "type", "action" ],
|
||||
"gestures": [ "info","menu" ]
|
||||
"uses": [ "type", "action", "location" ],
|
||||
"gestures": [ "info", "menu" ]
|
||||
},
|
||||
{
|
||||
"key": "object-header",
|
||||
@@ -88,12 +88,12 @@
|
||||
{
|
||||
"key": "navigationService",
|
||||
"implementation": "navigation/NavigationService.js"
|
||||
},
|
||||
},
|
||||
{
|
||||
"key": "creationService",
|
||||
"implementation": "creation/CreationService.js",
|
||||
"depends": [ "persistenceService", "$q", "$log" ]
|
||||
}
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
|
||||
@@ -27,12 +27,18 @@
|
||||
<mct-include key="_checkbox"></mct-include>
|
||||
</div>
|
||||
<div class='right abs'>
|
||||
<div class='ui-symbol icon alert hidden' onclick="alert('Not yet functional. When this is visible, it means that this object needs to be updated. Clicking will allow that action via a dialog.');">!</div>
|
||||
<div class='ui-symbol icon l-icon-alert'></div>
|
||||
<div class='ui-symbol icon profile' title="Shared">P</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='item-main abs'>
|
||||
<div class='ui-symbol icon lg abs item-type'>{{type.getGlyph()}}</div>
|
||||
<div class='ui-symbol icon lg item-type'>
|
||||
{{type.getGlyph()}}
|
||||
<span
|
||||
class="ui-symbol icon l-icon-link" title="This object is a link"
|
||||
ng-show="location.isLink()"
|
||||
></span>
|
||||
</div>
|
||||
<div class='ui-symbol icon abs item-open'>}</div>
|
||||
</div>
|
||||
<div class='bottom-bar bar abs'>
|
||||
@@ -44,4 +50,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining BrowseController. Created by vwoeltje on 11/7/14.
|
||||
* This bundle implements Browse mode.
|
||||
* @namespace platform/commonUI/browse
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
@@ -39,6 +40,7 @@ define(
|
||||
* which Angular templates first have access to the domain object
|
||||
* hierarchy.
|
||||
*
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function BrowseController($scope, $route, $location, objectService, navigationService, urlService) {
|
||||
@@ -157,3 +159,4 @@ define(
|
||||
return BrowseController;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ define(
|
||||
/**
|
||||
* Controller for the `browse-object` representation of a domain
|
||||
* object (the right-hand side of Browse mode.)
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function BrowseObjectController($scope, $location, $route) {
|
||||
@@ -71,3 +72,4 @@ define(
|
||||
return BrowseObjectController;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -33,19 +33,29 @@ define(
|
||||
* A left-click on the menu arrow should display a
|
||||
* context menu. This controller launches the context
|
||||
* menu.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function MenuArrowController($scope) {
|
||||
function showMenu(event) {
|
||||
var actionContext = {key: 'menu', domainObject: $scope.domainObject, event: event};
|
||||
$scope.domainObject.getCapability('action').perform(actionContext);
|
||||
}
|
||||
|
||||
return {
|
||||
showMenu: showMenu
|
||||
};
|
||||
this.$scope = $scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a context menu for the domain object in this scope.
|
||||
*
|
||||
* @param event the browser event which caused this (used to
|
||||
* position the menu)
|
||||
*/
|
||||
MenuArrowController.prototype.showMenu = function (event) {
|
||||
var actionContext = {
|
||||
key: 'menu',
|
||||
domainObject: this.$scope.domainObject,
|
||||
event: event
|
||||
};
|
||||
|
||||
this.$scope.domainObject.getCapability('action').perform(actionContext);
|
||||
};
|
||||
|
||||
return MenuArrowController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -34,7 +34,10 @@ define(
|
||||
* domain objects of a specific type. This is the action that
|
||||
* is performed when a user uses the Create menu.
|
||||
*
|
||||
* @memberof platform/commonUI/browse
|
||||
* @implements {Action}
|
||||
* @constructor
|
||||
*
|
||||
* @param {Type} type the type of domain object to create
|
||||
* @param {DomainObject} parent the domain object that should
|
||||
* act as a container for the newly-created object
|
||||
@@ -49,78 +52,84 @@ define(
|
||||
* of the newly-created domain object
|
||||
*/
|
||||
function CreateAction(type, parent, context, dialogService, creationService, policyService) {
|
||||
this.metadata = {
|
||||
key: 'create',
|
||||
glyph: type.getGlyph(),
|
||||
name: type.getName(),
|
||||
type: type.getKey(),
|
||||
description: type.getDescription(),
|
||||
context: context
|
||||
};
|
||||
|
||||
this.type = type;
|
||||
this.parent = parent;
|
||||
this.policyService = policyService;
|
||||
this.dialogService = dialogService;
|
||||
this.creationService = creationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new object of the given type.
|
||||
* This will prompt for user input first.
|
||||
*/
|
||||
CreateAction.prototype.perform = function () {
|
||||
/*
|
||||
Overview of steps in object creation:
|
||||
|
||||
1. Show dialog
|
||||
a. Prepare dialog contents
|
||||
b. Invoke dialogService
|
||||
a. Prepare dialog contents
|
||||
b. Invoke dialogService
|
||||
2. Create new object in persistence service
|
||||
a. Generate UUID
|
||||
b. Store model
|
||||
a. Generate UUID
|
||||
b. Store model
|
||||
3. Mutate destination container
|
||||
a. Get mutation capability
|
||||
b. Add new id to composition
|
||||
a. Get mutation capability
|
||||
b. Add new id to composition
|
||||
4. Persist destination container
|
||||
a. ...use persistence capability.
|
||||
a. ...use persistence capability.
|
||||
*/
|
||||
|
||||
function perform() {
|
||||
// The wizard will handle creating the form model based
|
||||
// on the type...
|
||||
var wizard = new CreateWizard(type, parent, policyService);
|
||||
// The wizard will handle creating the form model based
|
||||
// on the type...
|
||||
var wizard =
|
||||
new CreateWizard(this.type, this.parent, this.policyService),
|
||||
self = this;
|
||||
|
||||
// Create and persist the new object, based on user
|
||||
// input.
|
||||
function persistResult(formValue) {
|
||||
var parent = wizard.getLocation(formValue),
|
||||
newModel = wizard.createModel(formValue);
|
||||
return creationService.createObject(newModel, parent);
|
||||
}
|
||||
|
||||
function doNothing() {
|
||||
// Create cancelled, do nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
return dialogService.getUserInput(
|
||||
wizard.getFormStructure(),
|
||||
wizard.getInitialFormValue()
|
||||
).then(persistResult, doNothing);
|
||||
// Create and persist the new object, based on user
|
||||
// input.
|
||||
function persistResult(formValue) {
|
||||
var parent = wizard.getLocation(formValue),
|
||||
newModel = wizard.createModel(formValue);
|
||||
return self.creationService.createObject(newModel, parent);
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Create a new object of the given type.
|
||||
* This will prompt for user input first.
|
||||
* @method
|
||||
* @memberof CreateAction
|
||||
*/
|
||||
perform: perform,
|
||||
function doNothing() {
|
||||
// Create cancelled, do nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata about this action. This includes fields:
|
||||
* * `name`: Human-readable name
|
||||
* * `key`: Machine-readable identifier ("create")
|
||||
* * `glyph`: Glyph to use as an icon for this action
|
||||
* * `description`: Human-readable description
|
||||
* * `context`: The context in which this action will be performed.
|
||||
*
|
||||
* @return {object} metadata about the create action
|
||||
*/
|
||||
getMetadata: function () {
|
||||
return {
|
||||
key: 'create',
|
||||
glyph: type.getGlyph(),
|
||||
name: type.getName(),
|
||||
type: type.getKey(),
|
||||
description: type.getDescription(),
|
||||
context: context
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
return this.dialogService.getUserInput(
|
||||
wizard.getFormStructure(),
|
||||
wizard.getInitialFormValue()
|
||||
).then(persistResult, doNothing);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Metadata associated with a Create action.
|
||||
* @typedef {ActionMetadata} CreateActionMetadata
|
||||
* @property {string} type the key for the type of domain object
|
||||
* to be created
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get metadata about this action.
|
||||
* @returns {CreateActionMetadata} metadata about this action
|
||||
*/
|
||||
CreateAction.prototype.getMetadata = function () {
|
||||
return this.metadata;
|
||||
};
|
||||
|
||||
return CreateAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -33,7 +33,10 @@ define(
|
||||
* The CreateActionProvider is an ActionProvider which introduces
|
||||
* a Create action for each creatable domain object type.
|
||||
*
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
* @implements {ActionService}
|
||||
*
|
||||
* @param {TypeService} typeService the type service, used to discover
|
||||
* available types
|
||||
* @param {DialogService} dialogService the dialog service, used by
|
||||
@@ -44,44 +47,41 @@ define(
|
||||
* object creation.
|
||||
*/
|
||||
function CreateActionProvider(typeService, dialogService, creationService, policyService) {
|
||||
return {
|
||||
/**
|
||||
* Get all Create actions which are applicable in the provided
|
||||
* context.
|
||||
* @memberof CreateActionProvider
|
||||
* @method
|
||||
* @returns {CreateAction[]}
|
||||
*/
|
||||
getActions: function (actionContext) {
|
||||
var context = actionContext || {},
|
||||
key = context.key,
|
||||
destination = context.domainObject;
|
||||
|
||||
// We only provide Create actions, and we need a
|
||||
// domain object to serve as the container for the
|
||||
// newly-created object (although the user may later
|
||||
// make a different selection)
|
||||
if (key !== 'create' || !destination) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Introduce one create action per type
|
||||
return typeService.listTypes().filter(function (type) {
|
||||
return type.hasFeature("creation");
|
||||
}).map(function (type) {
|
||||
return new CreateAction(
|
||||
type,
|
||||
destination,
|
||||
context,
|
||||
dialogService,
|
||||
creationService,
|
||||
policyService
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
this.typeService = typeService;
|
||||
this.dialogService = dialogService;
|
||||
this.creationService = creationService;
|
||||
this.policyService = policyService;
|
||||
}
|
||||
|
||||
CreateActionProvider.prototype.getActions = function (actionContext) {
|
||||
var context = actionContext || {},
|
||||
key = context.key,
|
||||
destination = context.domainObject,
|
||||
self = this;
|
||||
|
||||
// We only provide Create actions, and we need a
|
||||
// domain object to serve as the container for the
|
||||
// newly-created object (although the user may later
|
||||
// make a different selection)
|
||||
if (key !== 'create' || !destination) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Introduce one create action per type
|
||||
return this.typeService.listTypes().filter(function (type) {
|
||||
return type.hasFeature("creation");
|
||||
}).map(function (type) {
|
||||
return new CreateAction(
|
||||
type,
|
||||
destination,
|
||||
context,
|
||||
self.dialogService,
|
||||
self.creationService,
|
||||
self.policyService
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
return CreateActionProvider;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -34,6 +34,7 @@ define(
|
||||
* set of Create actions based on the currently-selected
|
||||
* domain object.
|
||||
*
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function CreateMenuController($scope) {
|
||||
@@ -55,4 +56,4 @@ define(
|
||||
|
||||
return CreateMenuController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -21,12 +21,6 @@
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
/**
|
||||
* Defines the CreateWizard, used by the CreateAction to
|
||||
* populate the form shown in dialog based on the created type.
|
||||
*
|
||||
* @module core/action/create-wizard
|
||||
*/
|
||||
define(
|
||||
function () {
|
||||
'use strict';
|
||||
@@ -37,113 +31,118 @@ define(
|
||||
* @param {TypeImpl} type the type of domain object to be created
|
||||
* @param {DomainObject} parent the domain object to serve as
|
||||
* the initial parent for the created object, in the dialog
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
* @memberof module:core/action/create-wizard
|
||||
*/
|
||||
function CreateWizard(type, parent, policyService) {
|
||||
var model = type.getInitialModel(),
|
||||
properties = type.getProperties();
|
||||
this.type = type;
|
||||
this.model = type.getInitialModel();
|
||||
this.properties = type.getProperties();
|
||||
this.parent = parent;
|
||||
this.policyService = policyService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the form model for this wizard; this is a description
|
||||
* that will be rendered to an HTML form. See the
|
||||
* platform/forms bundle
|
||||
*
|
||||
* @return {FormModel} formModel the form model to
|
||||
* show in the create dialog
|
||||
*/
|
||||
CreateWizard.prototype.getFormStructure = function () {
|
||||
var sections = [],
|
||||
type = this.type,
|
||||
policyService = this.policyService;
|
||||
|
||||
function validateLocation(locatingObject) {
|
||||
var locatingType = locatingObject &&
|
||||
locatingObject.getCapability('type');
|
||||
locatingObject.getCapability('type');
|
||||
return locatingType && policyService.allow(
|
||||
"composition",
|
||||
locatingType,
|
||||
type
|
||||
);
|
||||
"composition",
|
||||
locatingType,
|
||||
type
|
||||
);
|
||||
}
|
||||
|
||||
sections.push({
|
||||
name: "Properties",
|
||||
rows: this.properties.map(function (property, index) {
|
||||
// Property definition is same as form row definition
|
||||
var row = Object.create(property.getDefinition());
|
||||
|
||||
// Use index as the key into the formValue;
|
||||
// this correlates to the indexing provided by
|
||||
// getInitialFormValue
|
||||
row.key = index;
|
||||
|
||||
return row;
|
||||
})
|
||||
});
|
||||
|
||||
// Ensure there is always a "save in" section
|
||||
sections.push({ name: 'Location', rows: [{
|
||||
name: "Save In",
|
||||
control: "locator",
|
||||
validate: validateLocation,
|
||||
key: "createParent"
|
||||
}]});
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the form model for this wizard; this is a description
|
||||
* that will be rendered to an HTML form. See the
|
||||
* platform/forms bundle
|
||||
*
|
||||
* @return {FormModel} formModel the form model to
|
||||
* show in the create dialog
|
||||
*/
|
||||
getFormStructure: function () {
|
||||
var sections = [];
|
||||
|
||||
sections.push({
|
||||
name: "Properties",
|
||||
rows: properties.map(function (property, index) {
|
||||
// Property definition is same as form row definition
|
||||
var row = Object.create(property.getDefinition());
|
||||
|
||||
// Use index as the key into the formValue;
|
||||
// this correlates to the indexing provided by
|
||||
// getInitialFormValue
|
||||
row.key = index;
|
||||
|
||||
return row;
|
||||
})
|
||||
});
|
||||
|
||||
// Ensure there is always a "save in" section
|
||||
sections.push({ name: 'Location', rows: [{
|
||||
name: "Save In",
|
||||
control: "locator",
|
||||
validate: validateLocation,
|
||||
key: "createParent"
|
||||
}]});
|
||||
|
||||
return {
|
||||
sections: sections,
|
||||
name: "Create a New " + type.getName()
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Get the initial value for the form being described.
|
||||
* This will include the values for all properties described
|
||||
* in the structure.
|
||||
*
|
||||
* @returns {object} the initial value of the form
|
||||
*/
|
||||
getInitialFormValue: function () {
|
||||
// Start with initial values for properties
|
||||
var formValue = properties.map(function (property) {
|
||||
return property.getValue(model);
|
||||
});
|
||||
|
||||
// Include the createParent
|
||||
formValue.createParent = parent;
|
||||
|
||||
return formValue;
|
||||
},
|
||||
/**
|
||||
* Based on a populated form, get the domain object which
|
||||
* should be used as a parent for the newly-created object.
|
||||
* @return {DomainObject}
|
||||
*/
|
||||
getLocation: function (formValue) {
|
||||
return formValue.createParent || parent;
|
||||
},
|
||||
/**
|
||||
* Create the domain object model for a newly-created object,
|
||||
* based on user input read from a formModel.
|
||||
* @return {object} the domain object' model
|
||||
*/
|
||||
createModel: function (formValue) {
|
||||
// Clone
|
||||
var newModel = JSON.parse(JSON.stringify(model));
|
||||
|
||||
// Always use the type from the type definition
|
||||
newModel.type = type.getKey();
|
||||
|
||||
// Update all properties
|
||||
properties.forEach(function (property, index) {
|
||||
property.setValue(newModel, formValue[index]);
|
||||
});
|
||||
|
||||
return newModel;
|
||||
}
|
||||
sections: sections,
|
||||
name: "Create a New " + this.type.getName()
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the initial value for the form being described.
|
||||
* This will include the values for all properties described
|
||||
* in the structure.
|
||||
*
|
||||
* @returns {object} the initial value of the form
|
||||
*/
|
||||
CreateWizard.prototype.getInitialFormValue = function () {
|
||||
// Start with initial values for properties
|
||||
var model = this.model,
|
||||
formValue = this.properties.map(function (property) {
|
||||
return property.getValue(model);
|
||||
});
|
||||
|
||||
}
|
||||
// Include the createParent
|
||||
formValue.createParent = this.parent;
|
||||
|
||||
return formValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Based on a populated form, get the domain object which
|
||||
* should be used as a parent for the newly-created object.
|
||||
* @return {DomainObject}
|
||||
*/
|
||||
CreateWizard.prototype.getLocation = function (formValue) {
|
||||
return formValue.createParent || this.parent;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the domain object model for a newly-created object,
|
||||
* based on user input read from a formModel.
|
||||
* @return {object} the domain object model
|
||||
*/
|
||||
CreateWizard.prototype.createModel = function (formValue) {
|
||||
// Clone
|
||||
var newModel = JSON.parse(JSON.stringify(this.model));
|
||||
|
||||
// Always use the type from the type definition
|
||||
newModel.type = this.type.getKey();
|
||||
|
||||
// Update all properties
|
||||
this.properties.forEach(function (property, index) {
|
||||
property.setValue(newModel, formValue[index]);
|
||||
});
|
||||
|
||||
return newModel;
|
||||
};
|
||||
|
||||
return CreateWizard;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -39,15 +39,45 @@ define(
|
||||
* persisting new domain objects. Handles all actual object
|
||||
* mutation and persistence associated with domain object
|
||||
* creation.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function CreationService(persistenceService, $q, $log) {
|
||||
this.persistenceService = persistenceService;
|
||||
this.$q = $q;
|
||||
this.$log = $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new domain object with the provided model, as
|
||||
* a member of the provided parent domain object's composition.
|
||||
* This parent will additionally determine which persistence
|
||||
* space an object is created within (as it is possible to
|
||||
* have multiple persistence spaces attached.)
|
||||
*
|
||||
* @param {object} model the model for the newly-created
|
||||
* domain object
|
||||
* @param {DomainObject} parent the domain object which
|
||||
* should contain the newly-created domain object
|
||||
* in its composition
|
||||
* @return {Promise} a promise that will resolve when the domain
|
||||
* object has been created
|
||||
*/
|
||||
CreationService.prototype.createObject = function (model, parent) {
|
||||
var persistence = parent.getCapability("persistence"),
|
||||
self = this;
|
||||
|
||||
// Store the location of an object relative to it's parent.
|
||||
function addLocationToModel(modelId, model, parent) {
|
||||
model.location = parent.getId();
|
||||
return model;
|
||||
}
|
||||
|
||||
// Persist the new domain object's model; it will be fully
|
||||
// constituted as a domain object when loaded back, as all
|
||||
// domain object models are.
|
||||
function doPersist(space, id, model) {
|
||||
return persistenceService.createObject(
|
||||
return self.persistenceService.createObject(
|
||||
space,
|
||||
id,
|
||||
model
|
||||
@@ -66,14 +96,14 @@ define(
|
||||
}
|
||||
} else {
|
||||
// This is abnormal; composition should be an array
|
||||
$log.warn(NO_COMPOSITION_WARNING + parent.getId());
|
||||
self.$log.warn(NO_COMPOSITION_WARNING + parent.getId());
|
||||
return false; // Cancel mutation
|
||||
}
|
||||
});
|
||||
|
||||
return $q.when(mutatationResult).then(function (result) {
|
||||
return self.$q.when(mutatationResult).then(function (result) {
|
||||
if (!result) {
|
||||
$log.error("Could not mutate " + parent.getId());
|
||||
self.$log.error("Could not mutate " + parent.getId());
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -93,49 +123,28 @@ define(
|
||||
});
|
||||
}
|
||||
|
||||
// Create a new domain object with the provided model as a
|
||||
// member of the specified parent's composition
|
||||
function createObject(model, parent) {
|
||||
var persistence = parent.getCapability("persistence");
|
||||
|
||||
// We need the parent's persistence capability to determine
|
||||
// what space to create the new object's model in.
|
||||
if (!persistence) {
|
||||
$log.warn(NON_PERSISTENT_WARNING);
|
||||
return $q.reject(new Error(NON_PERSISTENT_WARNING));
|
||||
}
|
||||
|
||||
// We create a new domain object in three sequential steps:
|
||||
// 1. Get a new UUID for the object
|
||||
// 2. Create a model with that ID in the persistence space
|
||||
// 3. Add that ID to
|
||||
return $q.when(
|
||||
uuid()
|
||||
).then(function (id) {
|
||||
return doPersist(persistence.getSpace(), id, model);
|
||||
}).then(function (id) {
|
||||
return addToComposition(id, parent, persistence);
|
||||
});
|
||||
// We need the parent's persistence capability to determine
|
||||
// what space to create the new object's model in.
|
||||
if (!persistence) {
|
||||
self.$log.warn(NON_PERSISTENT_WARNING);
|
||||
return self.$q.reject(new Error(NON_PERSISTENT_WARNING));
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Create a new domain object with the provided model, as
|
||||
* a member of the provided parent domain object's composition.
|
||||
* This parent will additionally determine which persistence
|
||||
* space an object is created within (as it is possible to
|
||||
* have multiple persistence spaces attached.)
|
||||
*
|
||||
* @param {object} model the model for the newly-created
|
||||
* domain object
|
||||
* @param {DomainObject} parent the domain object which
|
||||
* should contain the newly-created domain object
|
||||
* in its composition
|
||||
*/
|
||||
createObject: createObject
|
||||
};
|
||||
}
|
||||
// We create a new domain object in three sequential steps:
|
||||
// 1. Get a new UUID for the object
|
||||
// 2. Create a model with that ID in the persistence space
|
||||
// 3. Add that ID to
|
||||
return self.$q.when(uuid()).then(function (id) {
|
||||
model = addLocationToModel(id, model, parent);
|
||||
return doPersist(persistence.getSpace(), id, model);
|
||||
}).then(function (id) {
|
||||
return addToComposition(id, parent, persistence);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
return CreationService;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ define(
|
||||
* Controller for the "locator" control, which provides the
|
||||
* user with the ability to select a domain object as the
|
||||
* destination for a newly-created object in the Create menu.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function LocatorController($scope) {
|
||||
@@ -79,3 +80,4 @@ define(
|
||||
return LocatorController;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -31,32 +31,34 @@ define(
|
||||
|
||||
/**
|
||||
* The navigate action navigates to a specific domain object.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
*/
|
||||
function NavigateAction(navigationService, $q, context) {
|
||||
var domainObject = context.domainObject;
|
||||
|
||||
function perform() {
|
||||
// Set navigation, and wrap like a promise
|
||||
return $q.when(navigationService.setNavigation(domainObject));
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Navigate to the object described in the context.
|
||||
* @returns {Promise} a promise that is resolved once the
|
||||
* navigation has been updated
|
||||
*/
|
||||
perform: perform
|
||||
};
|
||||
this.domainObject = context.domainObject;
|
||||
this.$q = $q;
|
||||
this.navigationService = navigationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to the object described in the context.
|
||||
* @returns {Promise} a promise that is resolved once the
|
||||
* navigation has been updated
|
||||
*/
|
||||
NavigateAction.prototype.perform = function () {
|
||||
// Set navigation, and wrap like a promise
|
||||
return this.$q.when(
|
||||
this.navigationService.setNavigation(this.domainObject)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Navigate as an action is only applicable when a domain object
|
||||
* is described in the action context.
|
||||
* @param {ActionContext} context the context in which the action
|
||||
* will be performed
|
||||
* @returns true if applicable
|
||||
* @returns {boolean} true if applicable
|
||||
*/
|
||||
NavigateAction.appliesTo = function (context) {
|
||||
return context.domainObject !== undefined;
|
||||
@@ -64,4 +66,4 @@ define(
|
||||
|
||||
return NavigateAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -32,68 +32,58 @@ define(
|
||||
/**
|
||||
* The navigation service maintains the application's current
|
||||
* navigation state, and allows listening for changes thereto.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function NavigationService() {
|
||||
var navigated,
|
||||
callbacks = [];
|
||||
this.navigated = undefined;
|
||||
this.callbacks = [];
|
||||
}
|
||||
|
||||
// Getter for current navigation
|
||||
function getNavigation() {
|
||||
return navigated;
|
||||
}
|
||||
/**
|
||||
* Get the current navigation state.
|
||||
* @returns {DomainObject} the object that is navigated-to
|
||||
*/
|
||||
NavigationService.prototype.getNavigation = function () {
|
||||
return this.navigated;
|
||||
};
|
||||
|
||||
// Setter for navigation; invokes callbacks
|
||||
function setNavigation(value) {
|
||||
if (navigated !== value) {
|
||||
navigated = value;
|
||||
callbacks.forEach(function (callback) {
|
||||
callback(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a callback
|
||||
function addListener(callback) {
|
||||
callbacks.push(callback);
|
||||
}
|
||||
|
||||
// Filters out a callback
|
||||
function removeListener(callback) {
|
||||
callbacks = callbacks.filter(function (cb) {
|
||||
return cb !== callback;
|
||||
/**
|
||||
* Set the current navigation state. This will invoke listeners.
|
||||
* @param {DomainObject} domainObject the domain object to navigate to
|
||||
*/
|
||||
NavigationService.prototype.setNavigation = function (value) {
|
||||
if (this.navigated !== value) {
|
||||
this.navigated = value;
|
||||
this.callbacks.forEach(function (callback) {
|
||||
callback(value);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the current navigation state.
|
||||
*/
|
||||
getNavigation: getNavigation,
|
||||
/**
|
||||
* Set the current navigation state. Thiswill invoke listeners.
|
||||
* @param {DomainObject} value the domain object to navigate
|
||||
* to
|
||||
*/
|
||||
setNavigation: setNavigation,
|
||||
/**
|
||||
* Listen for changes in navigation. The passed callback will
|
||||
* be invoked with the new domain object of navigation when
|
||||
* this changes.
|
||||
* @param {function} callback the callback to invoke when
|
||||
* navigation state changes
|
||||
*/
|
||||
addListener: addListener,
|
||||
/**
|
||||
* Stop listening for changes in navigation state.
|
||||
* @param {function} callback the callback which should
|
||||
* no longer be invoked when navigation state
|
||||
* changes
|
||||
*/
|
||||
removeListener: removeListener
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Listen for changes in navigation. The passed callback will
|
||||
* be invoked with the new domain object of navigation when
|
||||
* this changes.
|
||||
* @param {function} callback the callback to invoke when
|
||||
* navigation state changes
|
||||
*/
|
||||
NavigationService.prototype.addListener = function (callback) {
|
||||
this.callbacks.push(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop listening for changes in navigation state.
|
||||
* @param {function} callback the callback which should
|
||||
* no longer be invoked when navigation state
|
||||
* changes
|
||||
*/
|
||||
NavigationService.prototype.removeListener = function (callback) {
|
||||
this.callbacks = this.callbacks.filter(function (cb) {
|
||||
return cb !== callback;
|
||||
});
|
||||
};
|
||||
|
||||
return NavigationService;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -35,36 +35,32 @@ define(
|
||||
/**
|
||||
* The fullscreen action toggles between fullscreen display
|
||||
* and regular in-window display.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
*/
|
||||
function FullscreenAction(context) {
|
||||
return {
|
||||
/**
|
||||
* Toggle full screen state
|
||||
*/
|
||||
perform: function () {
|
||||
screenfull.toggle();
|
||||
},
|
||||
/**
|
||||
* Get metadata about this action, including the
|
||||
* applicable glyph to display.
|
||||
*/
|
||||
getMetadata: function () {
|
||||
// We override getMetadata, because the glyph and
|
||||
// description need to be determined at run-time
|
||||
// based on whether or not we are currently
|
||||
// full screen.
|
||||
var metadata = Object.create(FullscreenAction);
|
||||
metadata.glyph = screenfull.isFullscreen ? "_" : "z";
|
||||
metadata.description = screenfull.isFullscreen ?
|
||||
EXIT_FULLSCREEN : ENTER_FULLSCREEN;
|
||||
metadata.group = "windowing";
|
||||
metadata.context = context;
|
||||
return metadata;
|
||||
}
|
||||
};
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
FullscreenAction.prototype.perform = function () {
|
||||
screenfull.toggle();
|
||||
};
|
||||
|
||||
FullscreenAction.prototype.getMetadata = function () {
|
||||
// We override getMetadata, because the glyph and
|
||||
// description need to be determined at run-time
|
||||
// based on whether or not we are currently
|
||||
// full screen.
|
||||
var metadata = Object.create(FullscreenAction);
|
||||
metadata.glyph = screenfull.isFullscreen ? "_" : "z";
|
||||
metadata.description = screenfull.isFullscreen ?
|
||||
EXIT_FULLSCREEN : ENTER_FULLSCREEN;
|
||||
metadata.group = "windowing";
|
||||
metadata.context = this.context;
|
||||
return metadata;
|
||||
};
|
||||
|
||||
return FullscreenAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -33,35 +33,29 @@ define(
|
||||
/**
|
||||
* The new tab action allows a domain object to be opened
|
||||
* into a new browser tab.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
*/
|
||||
function NewTabAction(urlService, $window, context) {
|
||||
// Returns the selected domain object
|
||||
// when using the context menu or the top right button
|
||||
// based on the context and the existance of the object
|
||||
// It is set to object an returned
|
||||
function getSelectedObject() {
|
||||
var object;
|
||||
if (context.selectedObject) {
|
||||
object = context.selectedObject;
|
||||
} else {
|
||||
object = context.domainObject;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
return {
|
||||
// Performs the open in new tab function
|
||||
// By calling the url service, the mode needed
|
||||
// (browse) and the domainObject is passed in and
|
||||
// the path is returned and opened in a new tab
|
||||
perform: function () {
|
||||
$window.open(urlService.urlForNewTab("browse", getSelectedObject()),
|
||||
"_blank");
|
||||
}
|
||||
context = context || {};
|
||||
|
||||
this.urlService = urlService;
|
||||
this.open = function () {
|
||||
$window.open.apply($window, arguments);
|
||||
};
|
||||
|
||||
// Choose the object to be opened into a new tab
|
||||
this.domainObject = context.selectedObject || context.domainObject;
|
||||
}
|
||||
|
||||
NewTabAction.prototype.perform = function () {
|
||||
this.open(
|
||||
this.urlService.urlForNewTab("browse", this.domainObject),
|
||||
"_blank"
|
||||
);
|
||||
};
|
||||
|
||||
return NewTabAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -29,6 +29,7 @@ define(
|
||||
/**
|
||||
* Updates the title of the current window to reflect the name
|
||||
* of the currently navigated-to domain object.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
function WindowTitler(navigationService, $rootScope, $document) {
|
||||
@@ -49,4 +50,4 @@ define(
|
||||
|
||||
return WindowTitler;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -38,6 +38,7 @@ define(
|
||||
mockMutationCapability,
|
||||
mockPersistenceCapability,
|
||||
mockCompositionCapability,
|
||||
mockContextCapability,
|
||||
mockCapabilities,
|
||||
creationService;
|
||||
|
||||
@@ -87,10 +88,15 @@ define(
|
||||
"composition",
|
||||
["invoke"]
|
||||
);
|
||||
mockContextCapability = jasmine.createSpyObj(
|
||||
"context",
|
||||
["getPath"]
|
||||
);
|
||||
mockCapabilities = {
|
||||
mutation: mockMutationCapability,
|
||||
persistence: mockPersistenceCapability,
|
||||
composition: mockCompositionCapability
|
||||
composition: mockCompositionCapability,
|
||||
context: mockContextCapability
|
||||
};
|
||||
|
||||
mockPersistenceService.createObject.andReturn(
|
||||
@@ -103,6 +109,7 @@ define(
|
||||
mockParentObject.useCapability.andCallFake(function (key, value) {
|
||||
return mockCapabilities[key].invoke(value);
|
||||
});
|
||||
mockParentObject.getId.andReturn('parentId');
|
||||
|
||||
mockPersistenceCapability.persist.andReturn(
|
||||
mockPromise(true)
|
||||
@@ -194,7 +201,16 @@ define(
|
||||
expect(mockLog.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("stores location on new domainObjects", function () {
|
||||
var model = { name: "my model" },
|
||||
objectPromise = creationService.createObject(
|
||||
model,
|
||||
mockParentObject
|
||||
);
|
||||
|
||||
expect(model.location).toBe('parentId');
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
/*global define*/
|
||||
|
||||
/**
|
||||
* Module defining DialogService. Created by vwoeltje on 11/10/14.
|
||||
* This bundle implements the dialog service, which can be used to
|
||||
* launch dialogs for user input & notifications.
|
||||
* @namespace platform/commonUI/dialog
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
@@ -32,128 +34,130 @@ define(
|
||||
* The dialog service is responsible for handling window-modal
|
||||
* communication with the user, such as displaying forms for user
|
||||
* input.
|
||||
* @memberof platform/commonUI/dialog
|
||||
* @constructor
|
||||
*/
|
||||
function DialogService(overlayService, $q, $log) {
|
||||
var overlay,
|
||||
dialogVisible = false;
|
||||
|
||||
// Stop showing whatever overlay is currently active
|
||||
// (e.g. because the user hit cancel)
|
||||
function dismiss() {
|
||||
if (overlay) {
|
||||
overlay.dismiss();
|
||||
}
|
||||
dialogVisible = false;
|
||||
}
|
||||
|
||||
function getDialogResponse(key, model, resultGetter) {
|
||||
// We will return this result as a promise, because user
|
||||
// input is asynchronous.
|
||||
var deferred = $q.defer(),
|
||||
overlayModel;
|
||||
|
||||
// Confirm function; this will be passed in to the
|
||||
// overlay-dialog template and associated with a
|
||||
// OK button click
|
||||
function confirm(value) {
|
||||
// Pass along the result
|
||||
deferred.resolve(resultGetter ? resultGetter() : value);
|
||||
|
||||
// Stop showing the dialog
|
||||
dismiss();
|
||||
}
|
||||
|
||||
// Cancel function; this will be passed in to the
|
||||
// overlay-dialog template and associated with a
|
||||
// Cancel or X button click
|
||||
function cancel() {
|
||||
deferred.reject();
|
||||
dismiss();
|
||||
}
|
||||
|
||||
// Add confirm/cancel callbacks
|
||||
model.confirm = confirm;
|
||||
model.cancel = cancel;
|
||||
|
||||
if (dialogVisible) {
|
||||
// Only one dialog should be shown at a time.
|
||||
// The application design should be such that
|
||||
// we never even try to do this.
|
||||
$log.warn([
|
||||
"Dialog already showing; ",
|
||||
"unable to show ",
|
||||
model.name
|
||||
].join(""));
|
||||
deferred.reject();
|
||||
} else {
|
||||
// Add the overlay using the OverlayService, which
|
||||
// will handle actual insertion into the DOM
|
||||
overlay = overlayService.createOverlay(
|
||||
key,
|
||||
model
|
||||
);
|
||||
|
||||
// Track that a dialog is already visible, to
|
||||
// avoid spawning multiple dialogs at once.
|
||||
dialogVisible = true;
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function getUserInput(formModel, value) {
|
||||
var overlayModel = {
|
||||
title: formModel.name,
|
||||
message: formModel.message,
|
||||
structure: formModel,
|
||||
value: value
|
||||
};
|
||||
|
||||
// Provide result from the model
|
||||
function resultGetter() {
|
||||
return overlayModel.value;
|
||||
}
|
||||
|
||||
// Show the overlay-dialog
|
||||
return getDialogResponse(
|
||||
"overlay-dialog",
|
||||
overlayModel,
|
||||
resultGetter
|
||||
);
|
||||
}
|
||||
|
||||
function getUserChoice(dialogModel) {
|
||||
// Show the overlay-options dialog
|
||||
return getDialogResponse(
|
||||
"overlay-options",
|
||||
{ dialog: dialogModel }
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Request user input via a window-modal dialog.
|
||||
*
|
||||
* @param {FormModel} formModel a description of the form
|
||||
* to be shown (see platform/forms)
|
||||
* @param {object} value the initial state of the form
|
||||
* @returns {Promise} a promsie for the form value that the
|
||||
* user has supplied; this may be rejected if
|
||||
* user input cannot be obtained (for instance,
|
||||
* because the user cancelled the dialog)
|
||||
*/
|
||||
getUserInput: getUserInput,
|
||||
/**
|
||||
* Request that the user chooses from a set of options,
|
||||
* which will be shown as buttons.
|
||||
*
|
||||
* @param dialogModel a description of the dialog to show
|
||||
*/
|
||||
getUserChoice: getUserChoice
|
||||
};
|
||||
this.overlayService = overlayService;
|
||||
this.$q = $q;
|
||||
this.$log = $log;
|
||||
this.overlay = undefined;
|
||||
this.dialogVisible = false;
|
||||
}
|
||||
|
||||
// Stop showing whatever overlay is currently active
|
||||
// (e.g. because the user hit cancel)
|
||||
DialogService.prototype.dismiss = function () {
|
||||
var overlay = this.overlay;
|
||||
if (overlay) {
|
||||
overlay.dismiss();
|
||||
}
|
||||
this.dialogVisible = false;
|
||||
};
|
||||
|
||||
DialogService.prototype.getDialogResponse = function (key, model, resultGetter) {
|
||||
// We will return this result as a promise, because user
|
||||
// input is asynchronous.
|
||||
var deferred = this.$q.defer(),
|
||||
self = this;
|
||||
|
||||
// Confirm function; this will be passed in to the
|
||||
// overlay-dialog template and associated with a
|
||||
// OK button click
|
||||
function confirm(value) {
|
||||
// Pass along the result
|
||||
deferred.resolve(resultGetter ? resultGetter() : value);
|
||||
|
||||
// Stop showing the dialog
|
||||
self.dismiss();
|
||||
}
|
||||
|
||||
// Cancel function; this will be passed in to the
|
||||
// overlay-dialog template and associated with a
|
||||
// Cancel or X button click
|
||||
function cancel() {
|
||||
deferred.reject();
|
||||
self.dismiss();
|
||||
}
|
||||
|
||||
// Add confirm/cancel callbacks
|
||||
model.confirm = confirm;
|
||||
model.cancel = cancel;
|
||||
|
||||
if (this.dialogVisible) {
|
||||
// Only one dialog should be shown at a time.
|
||||
// The application design should be such that
|
||||
// we never even try to do this.
|
||||
this.$log.warn([
|
||||
"Dialog already showing; ",
|
||||
"unable to show ",
|
||||
model.name
|
||||
].join(""));
|
||||
deferred.reject();
|
||||
} else {
|
||||
// Add the overlay using the OverlayService, which
|
||||
// will handle actual insertion into the DOM
|
||||
this.overlay = this.overlayService.createOverlay(
|
||||
key,
|
||||
model
|
||||
);
|
||||
|
||||
// Track that a dialog is already visible, to
|
||||
// avoid spawning multiple dialogs at once.
|
||||
this.dialogVisible = true;
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Request user input via a window-modal dialog.
|
||||
*
|
||||
* @param {FormModel} formModel a description of the form
|
||||
* to be shown (see platform/forms)
|
||||
* @param {object} value the initial state of the form
|
||||
* @returns {Promise} a promise for the form value that the
|
||||
* user has supplied; this may be rejected if
|
||||
* user input cannot be obtained (for instance,
|
||||
* because the user cancelled the dialog)
|
||||
*/
|
||||
DialogService.prototype.getUserInput = function (formModel, value) {
|
||||
var overlayModel = {
|
||||
title: formModel.name,
|
||||
message: formModel.message,
|
||||
structure: formModel,
|
||||
value: value
|
||||
};
|
||||
|
||||
// Provide result from the model
|
||||
function resultGetter() {
|
||||
return overlayModel.value;
|
||||
}
|
||||
|
||||
// Show the overlay-dialog
|
||||
return this.getDialogResponse(
|
||||
"overlay-dialog",
|
||||
overlayModel,
|
||||
resultGetter
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Request that the user chooses from a set of options,
|
||||
* which will be shown as buttons.
|
||||
*
|
||||
* @param dialogModel a description of the dialog to show
|
||||
* @return {Promise} a promise for the user's choice
|
||||
*/
|
||||
DialogService.prototype.getUserChoice = function (dialogModel) {
|
||||
// Show the overlay-options dialog
|
||||
return this.getDialogResponse(
|
||||
"overlay-options",
|
||||
{ dialog: dialogModel }
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
return DialogService;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -43,57 +43,63 @@ define(
|
||||
* particularly where a multiple-overlay effect is not specifically
|
||||
* desired).
|
||||
*
|
||||
* @memberof platform/commonUI/dialog
|
||||
* @constructor
|
||||
*/
|
||||
function OverlayService($document, $compile, $rootScope) {
|
||||
function createOverlay(key, overlayModel) {
|
||||
// Create a new scope for this overlay
|
||||
var scope = $rootScope.$new(),
|
||||
element;
|
||||
this.$compile = $compile;
|
||||
|
||||
// Stop showing the overlay; additionally, release the scope
|
||||
// that it uses.
|
||||
function dismiss() {
|
||||
scope.$destroy();
|
||||
element.remove();
|
||||
}
|
||||
|
||||
// If no model is supplied, just fill in a default "cancel"
|
||||
overlayModel = overlayModel || { cancel: dismiss };
|
||||
|
||||
// Populate the scope; will be passed directly to the template
|
||||
scope.overlay = overlayModel;
|
||||
scope.key = key;
|
||||
|
||||
// Create the overlay element and add it to the document's body
|
||||
element = $compile(TEMPLATE)(scope);
|
||||
$document.find('body').prepend(element);
|
||||
|
||||
|
||||
|
||||
return {
|
||||
dismiss: dismiss
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Add a new overlay to the document. This will be
|
||||
* prepended to the document body; the overlay's
|
||||
* template (as pointed to by the `key` argument) is
|
||||
* responsible for having a useful z-order, and for
|
||||
* blocking user interactions if appropriate.
|
||||
*
|
||||
* @param {string} key the symbolic key which identifies
|
||||
* the template of the overlay to be shown
|
||||
* @param {object} overlayModel the model to pass to the
|
||||
* included overlay template (this will be passed
|
||||
* in via ng-model)
|
||||
*/
|
||||
createOverlay: createOverlay
|
||||
// Don't include $document and $rootScope directly;
|
||||
// avoids https://docs.angularjs.org/error/ng/cpws
|
||||
this.findBody = function () {
|
||||
return $document.find('body');
|
||||
};
|
||||
this.newScope = function () {
|
||||
return $rootScope.$new();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new overlay to the document. This will be
|
||||
* prepended to the document body; the overlay's
|
||||
* template (as pointed to by the `key` argument) is
|
||||
* responsible for having a useful z-order, and for
|
||||
* blocking user interactions if appropriate.
|
||||
*
|
||||
* @param {string} key the symbolic key which identifies
|
||||
* the template of the overlay to be shown
|
||||
* @param {object} overlayModel the model to pass to the
|
||||
* included overlay template (this will be passed
|
||||
* in via ng-model)
|
||||
*/
|
||||
OverlayService.prototype.createOverlay = function (key, overlayModel) {
|
||||
// Create a new scope for this overlay
|
||||
var scope = this.newScope(),
|
||||
element;
|
||||
|
||||
// Stop showing the overlay; additionally, release the scope
|
||||
// that it uses.
|
||||
function dismiss() {
|
||||
scope.$destroy();
|
||||
element.remove();
|
||||
}
|
||||
|
||||
// If no model is supplied, just fill in a default "cancel"
|
||||
overlayModel = overlayModel || { cancel: dismiss };
|
||||
|
||||
// Populate the scope; will be passed directly to the template
|
||||
scope.overlay = overlayModel;
|
||||
scope.key = key;
|
||||
|
||||
// Create the overlay element and add it to the document's body
|
||||
element = this.$compile(TEMPLATE)(scope);
|
||||
this.findBody().prepend(element);
|
||||
|
||||
return {
|
||||
dismiss: dismiss
|
||||
};
|
||||
};
|
||||
|
||||
return OverlayService;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -29,9 +29,26 @@ define(
|
||||
* The "Cancel" action; the action triggered by clicking Cancel from
|
||||
* Edit Mode. Exits the editing user interface and invokes object
|
||||
* capabilities to persist the changes that have been made.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Action}
|
||||
*/
|
||||
function CancelAction($location, urlService, context) {
|
||||
var domainObject = context.domainObject;
|
||||
this.domainObject = context.domainObject;
|
||||
this.$location = $location;
|
||||
this.urlService = urlService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel editing.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
*/
|
||||
CancelAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject,
|
||||
$location = this.$location,
|
||||
urlService = this.urlService;
|
||||
|
||||
// Look up the object's "editor.completion" capability;
|
||||
// this is introduced by EditableDomainObject which is
|
||||
@@ -56,25 +73,15 @@ define(
|
||||
)));
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Cancel editing.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
*/
|
||||
perform: function () {
|
||||
return doCancel(getEditorCapability())
|
||||
.then(returnToBrowse);
|
||||
}
|
||||
};
|
||||
}
|
||||
return doCancel(getEditorCapability())
|
||||
.then(returnToBrowse);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this action is applicable in a given context.
|
||||
* This will ensure that a domain object is present in the context,
|
||||
* and that this domain object is in Edit mode.
|
||||
* @returns true if applicable
|
||||
* @returns {boolean} true if applicable
|
||||
*/
|
||||
CancelAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
@@ -84,4 +91,4 @@ define(
|
||||
|
||||
return CancelAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -42,7 +42,9 @@ define(
|
||||
* mode (typically triggered by the Edit button.) This will
|
||||
* show the user interface for editing (by way of a change in
|
||||
* route)
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
*/
|
||||
function EditAction($location, navigationService, $log, context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
@@ -60,17 +62,19 @@ define(
|
||||
return NULL_ACTION;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Enter edit mode.
|
||||
*/
|
||||
perform: function () {
|
||||
navigationService.setNavigation(domainObject);
|
||||
$location.path("/edit");
|
||||
}
|
||||
};
|
||||
this.domainObject = domainObject;
|
||||
this.$location = $location;
|
||||
this.navigationService = navigationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter edit mode.
|
||||
*/
|
||||
EditAction.prototype.perform = function () {
|
||||
this.navigationService.setNavigation(this.domainObject);
|
||||
this.$location.path("/edit");
|
||||
};
|
||||
|
||||
/**
|
||||
* Check for applicability; verify that a domain object is present
|
||||
* for this action to be performed upon.
|
||||
@@ -87,4 +91,4 @@ define(
|
||||
|
||||
return EditAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -29,42 +29,43 @@ define(
|
||||
|
||||
/**
|
||||
* Add one domain object to another's composition.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Action}
|
||||
*/
|
||||
function LinkAction(context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
selectedObject = (context || {}).selectedObject,
|
||||
selectedId = selectedObject && selectedObject.getId();
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.selectedObject = (context || {}).selectedObject;
|
||||
this.selectedId = this.selectedObject && this.selectedObject.getId();
|
||||
}
|
||||
|
||||
LinkAction.prototype.perform = function () {
|
||||
var self = this;
|
||||
|
||||
// Add this domain object's identifier
|
||||
function addId(model) {
|
||||
if (Array.isArray(model.composition) &&
|
||||
model.composition.indexOf(selectedId) < 0) {
|
||||
model.composition.push(selectedId);
|
||||
model.composition.indexOf(self.selectedId) < 0) {
|
||||
model.composition.push(self.selectedId);
|
||||
}
|
||||
}
|
||||
|
||||
// Persist changes to the domain object
|
||||
function doPersist() {
|
||||
var persistence = domainObject.getCapability('persistence');
|
||||
var persistence =
|
||||
self.domainObject.getCapability('persistence');
|
||||
return persistence.persist();
|
||||
}
|
||||
|
||||
// Link these objects
|
||||
function doLink() {
|
||||
return domainObject.useCapability("mutation", addId)
|
||||
return self.domainObject.useCapability("mutation", addId)
|
||||
.then(doPersist);
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Perform this action.
|
||||
*/
|
||||
perform: function () {
|
||||
return selectedId && doLink();
|
||||
}
|
||||
};
|
||||
}
|
||||
return this.selectedId && doLink();
|
||||
};
|
||||
|
||||
return LinkAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -32,58 +32,58 @@ define(
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Construct an action which will allow an object's metadata to be
|
||||
* edited.
|
||||
* Implements the "Edit Properties" action, which prompts the user
|
||||
* to modify a domain object's properties.
|
||||
*
|
||||
* @param {DialogService} dialogService a service which will show the dialog
|
||||
* @param {DomainObject} object the object to be edited
|
||||
* @param {ActionContext} context the context in which this action is performed
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Action}
|
||||
* @constructor
|
||||
*/
|
||||
function PropertiesAction(dialogService, context) {
|
||||
var object = context.domainObject;
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.dialogService = dialogService;
|
||||
}
|
||||
|
||||
PropertiesAction.prototype.perform = function () {
|
||||
var type = this.domainObject.getCapability('type'),
|
||||
domainObject = this.domainObject,
|
||||
dialogService = this.dialogService;
|
||||
|
||||
// Persist modifications to this domain object
|
||||
function doPersist() {
|
||||
var persistence = object.getCapability('persistence');
|
||||
var persistence = domainObject.getCapability('persistence');
|
||||
return persistence && persistence.persist();
|
||||
}
|
||||
|
||||
// Update the domain object model based on user input
|
||||
function updateModel(userInput, dialog) {
|
||||
return object.useCapability('mutation', function (model) {
|
||||
return domainObject.useCapability('mutation', function (model) {
|
||||
dialog.updateModel(model, userInput);
|
||||
});
|
||||
}
|
||||
|
||||
function showDialog(type) {
|
||||
// Create a dialog object to generate the form structure, etc.
|
||||
var dialog = new PropertiesDialog(type, object.getModel());
|
||||
var dialog =
|
||||
new PropertiesDialog(type, domainObject.getModel());
|
||||
|
||||
// Show the dialog
|
||||
return dialogService.getUserInput(
|
||||
dialog.getFormStructure(),
|
||||
dialog.getInitialFormValue()
|
||||
).then(function (userInput) {
|
||||
// Update the model, if user input was provided
|
||||
return userInput && updateModel(userInput, dialog);
|
||||
}).then(function (result) {
|
||||
return result && doPersist();
|
||||
});
|
||||
// Update the model, if user input was provided
|
||||
return userInput && updateModel(userInput, dialog);
|
||||
}).then(function (result) {
|
||||
return result && doPersist();
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Perform this action.
|
||||
* @return {Promise} a promise which will be
|
||||
* fulfilled when the action has completed.
|
||||
*/
|
||||
perform: function () {
|
||||
var type = object.getCapability('type');
|
||||
return type && showDialog(type);
|
||||
}
|
||||
};
|
||||
}
|
||||
return type && showDialog(type);
|
||||
};
|
||||
|
||||
/**
|
||||
* Filter this action for applicability against a given context.
|
||||
@@ -106,3 +106,4 @@ define(
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -21,12 +21,6 @@
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
/**
|
||||
* Defines the PropertiesDialog, used by the PropertiesAction to
|
||||
* populate the form shown in dialog based on the created type.
|
||||
*
|
||||
* @module common/actions/properties-dialog
|
||||
*/
|
||||
define(
|
||||
function () {
|
||||
'use strict';
|
||||
@@ -37,58 +31,60 @@ define(
|
||||
* @param {TypeImpl} type the type of domain object for which properties
|
||||
* will be specified
|
||||
* @param {DomainObject} the object for which properties will be set
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @memberof module:common/actions/properties-dialog
|
||||
*/
|
||||
function PropertiesDialog(type, model) {
|
||||
var properties = type.getProperties();
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get sections provided by this dialog.
|
||||
* @return {FormStructure} the structure of this form
|
||||
*/
|
||||
getFormStructure: function () {
|
||||
return {
|
||||
name: "Edit " + model.name,
|
||||
sections: [{
|
||||
name: "Properties",
|
||||
rows: properties.map(function (property, index) {
|
||||
// Property definition is same as form row definition
|
||||
var row = Object.create(property.getDefinition());
|
||||
row.key = index;
|
||||
return row;
|
||||
})
|
||||
}]
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Get the initial state of the form shown by this dialog
|
||||
* (based on the object model)
|
||||
* @returns {object} initial state of the form
|
||||
*/
|
||||
getInitialFormValue: function () {
|
||||
// Start with initial values for properties
|
||||
// Note that index needs to correlate to row.key
|
||||
// from getFormStructure
|
||||
return properties.map(function (property) {
|
||||
return property.getValue(model);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Update a domain object model based on the value of a form.
|
||||
*/
|
||||
updateModel: function (model, formValue) {
|
||||
// Update all properties
|
||||
properties.forEach(function (property, index) {
|
||||
property.setValue(model, formValue[index]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.type = type;
|
||||
this.model = model;
|
||||
this.properties = type.getProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sections provided by this dialog.
|
||||
* @return {FormStructure} the structure of this form
|
||||
*/
|
||||
PropertiesDialog.prototype.getFormStructure = function () {
|
||||
return {
|
||||
name: "Edit " + this.model.name,
|
||||
sections: [{
|
||||
name: "Properties",
|
||||
rows: this.properties.map(function (property, index) {
|
||||
// Property definition is same as form row definition
|
||||
var row = Object.create(property.getDefinition());
|
||||
row.key = index;
|
||||
return row;
|
||||
})
|
||||
}]
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the initial state of the form shown by this dialog
|
||||
* (based on the object model)
|
||||
* @returns {object} initial state of the form
|
||||
*/
|
||||
PropertiesDialog.prototype.getInitialFormValue = function () {
|
||||
var model = this.model;
|
||||
|
||||
// Start with initial values for properties
|
||||
// Note that index needs to correlate to row.key
|
||||
// from getFormStructure
|
||||
return this.properties.map(function (property) {
|
||||
return property.getValue(model);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Update a domain object model based on the value of a form.
|
||||
*/
|
||||
PropertiesDialog.prototype.updateModel = function (model, formValue) {
|
||||
// Update all properties
|
||||
this.properties.forEach(function (property, index) {
|
||||
property.setValue(model, formValue[index]);
|
||||
});
|
||||
};
|
||||
|
||||
return PropertiesDialog;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -37,22 +37,34 @@ define(
|
||||
*
|
||||
* @param {DomainObject} object the object to be removed
|
||||
* @param {ActionContext} context the context in which this action is performed
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @memberof module:editor/actions/remove-action
|
||||
* @implements {Action}
|
||||
*/
|
||||
function RemoveAction($q, context) {
|
||||
var object = (context || {}).domainObject;
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.$q = $q;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Perform this action.
|
||||
* @return {Promise} a promise which will be
|
||||
* fulfilled when the action has completed.
|
||||
*/
|
||||
RemoveAction.prototype.perform = function () {
|
||||
var $q = this.$q,
|
||||
domainObject = this.domainObject;
|
||||
|
||||
/*
|
||||
* Check whether an object ID matches the ID of the object being
|
||||
* removed (used to filter a parent's composition to handle the
|
||||
* removal.)
|
||||
*/
|
||||
function isNotObject(otherObjectId) {
|
||||
return otherObjectId !== object.getId();
|
||||
return otherObjectId !== domainObject.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Mutate a parent object such that it no longer contains the object
|
||||
* which is being removed.
|
||||
*/
|
||||
@@ -60,7 +72,7 @@ define(
|
||||
model.composition = model.composition.filter(isNotObject);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Invoke persistence on a domain object. This will be called upon
|
||||
* the removed object's parent (as its composition will have changed.)
|
||||
*/
|
||||
@@ -69,33 +81,22 @@ define(
|
||||
return persistence && persistence.persist();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Remove the object from its parent, as identified by its context
|
||||
* capability.
|
||||
* @param {ContextCapability} contextCapability the "context" capability
|
||||
* of the domain object being removed.
|
||||
*/
|
||||
function removeFromContext(contextCapability) {
|
||||
var parent = contextCapability.getParent();
|
||||
$q.when(
|
||||
parent.useCapability('mutation', doMutate)
|
||||
).then(function () {
|
||||
return doPersist(parent);
|
||||
});
|
||||
return $q.when(
|
||||
parent.useCapability('mutation', doMutate)
|
||||
).then(function () {
|
||||
return doPersist(parent);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Perform this action.
|
||||
* @return {module:core/promises.Promise} a promise which will be
|
||||
* fulfilled when the action has completed.
|
||||
*/
|
||||
perform: function () {
|
||||
return $q.when(object.getCapability('context'))
|
||||
.then(removeFromContext);
|
||||
}
|
||||
};
|
||||
}
|
||||
return $q.when(this.domainObject.getCapability('context'))
|
||||
.then(removeFromContext);
|
||||
};
|
||||
|
||||
// Object needs to have a parent for Remove to be applicable
|
||||
RemoveAction.appliesTo = function (context) {
|
||||
@@ -113,4 +114,4 @@ define(
|
||||
|
||||
return RemoveAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -30,9 +30,27 @@ define(
|
||||
* The "Save" action; the action triggered by clicking Save from
|
||||
* Edit Mode. Exits the editing user interface and invokes object
|
||||
* capabilities to persist the changes that have been made.
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
* @memberof platform/commonUI/edit
|
||||
*/
|
||||
function SaveAction($location, urlService, context) {
|
||||
var domainObject = context.domainObject;
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.$location = $location;
|
||||
this.urlService = urlService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save changes and conclude editing.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
* @memberof platform/commonUI/edit.SaveAction#
|
||||
*/
|
||||
SaveAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject,
|
||||
$location = this.$location,
|
||||
urlService = this.urlService;
|
||||
|
||||
// Invoke any save behavior introduced by the editor capability;
|
||||
// this is introduced by EditableDomainObject which is
|
||||
@@ -51,18 +69,8 @@ define(
|
||||
));
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Save changes and conclude editing.
|
||||
*
|
||||
* @returns {Promise} a promise that will be fulfilled when
|
||||
* cancellation has completed
|
||||
*/
|
||||
perform: function () {
|
||||
return doSave().then(returnToBrowse);
|
||||
}
|
||||
};
|
||||
}
|
||||
return doSave().then(returnToBrowse);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this action is applicable in a given context.
|
||||
@@ -78,4 +86,4 @@ define(
|
||||
|
||||
return SaveAction;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -35,6 +35,9 @@ define(
|
||||
* Meant specifically for use by EditableDomainObject and the
|
||||
* associated cache; the constructor signature is particular
|
||||
* to a pattern used there and may contain unused arguments.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {CompositionCapability}
|
||||
*/
|
||||
return function EditableCompositionCapability(
|
||||
contextCapability,
|
||||
@@ -54,4 +57,4 @@ define(
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -35,6 +35,9 @@ define(
|
||||
* Meant specifically for use by EditableDomainObject and the
|
||||
* associated cache; the constructor signature is particular
|
||||
* to a pattern used there and may contain unused arguments.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {ContextCapability}
|
||||
*/
|
||||
return function EditableContextCapability(
|
||||
contextCapability,
|
||||
@@ -72,4 +75,4 @@ define(
|
||||
return capability;
|
||||
};
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -35,6 +35,8 @@ define(
|
||||
* Meant specifically for use by EditableDomainObject and the
|
||||
* associated cache; the constructor signature is particular
|
||||
* to a pattern used there and may contain unused arguments.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
*/
|
||||
return function EditableLookupCapability(
|
||||
contextCapability,
|
||||
@@ -76,7 +78,7 @@ define(
|
||||
// Wrap a returned value (see above); if it's a promise, wrap
|
||||
// the resolved value.
|
||||
function wrapResult(result) {
|
||||
return result.then ? // promise-like
|
||||
return (result && result.then) ? // promise-like
|
||||
result.then(makeEditable) :
|
||||
makeEditable(result);
|
||||
}
|
||||
@@ -105,8 +107,10 @@ define(
|
||||
|
||||
// Wrap a method of this capability
|
||||
function wrapMethod(fn) {
|
||||
capability[fn] =
|
||||
(idempotent ? oneTimeFunction : wrapFunction)(fn);
|
||||
if (typeof capability[fn] === 'function') {
|
||||
capability[fn] =
|
||||
(idempotent ? oneTimeFunction : wrapFunction)(fn);
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap all methods; return only editable domain objects.
|
||||
@@ -115,4 +119,4 @@ define(
|
||||
return capability;
|
||||
};
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -35,6 +35,9 @@ define(
|
||||
* Meant specifically for use by EditableDomainObject and the
|
||||
* associated cache; the constructor signature is particular
|
||||
* to a pattern used there and may contain unused arguments.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {PersistenceCapability}
|
||||
*/
|
||||
function EditablePersistenceCapability(
|
||||
persistenceCapability,
|
||||
@@ -62,4 +65,4 @@ define(
|
||||
|
||||
return EditablePersistenceCapability;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -35,6 +35,9 @@ define(
|
||||
* Meant specifically for use by EditableDomainObject and the
|
||||
* associated cache; the constructor signature is particular
|
||||
* to a pattern used there and may contain unused arguments.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {RelationshipCapability}
|
||||
*/
|
||||
return function EditableRelationshipCapability(
|
||||
relationshipCapability,
|
||||
@@ -54,4 +57,4 @@ define(
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -39,27 +39,48 @@ define(
|
||||
* Meant specifically for use by EditableDomainObject and the
|
||||
* associated cache; the constructor signature is particular
|
||||
* to a pattern used there and may contain unused arguments.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
*/
|
||||
return function EditorCapability(
|
||||
function EditorCapability(
|
||||
persistenceCapability,
|
||||
editableObject,
|
||||
domainObject,
|
||||
cache
|
||||
) {
|
||||
this.editableObject = editableObject;
|
||||
this.domainObject = domainObject;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
// Simulate Promise.resolve (or $q.when); the former
|
||||
// causes a delayed reaction from Angular (since it
|
||||
// does not trigger a digest) and the latter is not
|
||||
// readily accessible, since we're a few classes
|
||||
// removed from the layer which gets dependency
|
||||
// injection.
|
||||
function resolvePromise(value) {
|
||||
return (value && value.then) ? value : {
|
||||
then: function (callback) {
|
||||
return resolvePromise(callback(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
// Simulate Promise.resolve (or $q.when); the former
|
||||
// causes a delayed reaction from Angular (since it
|
||||
// does not trigger a digest) and the latter is not
|
||||
// readily accessible, since we're a few classes
|
||||
// removed from the layer which gets dependency
|
||||
// injection.
|
||||
function resolvePromise(value) {
|
||||
return (value && value.then) ? value : {
|
||||
then: function (callback) {
|
||||
return resolvePromise(callback(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Save any changes that have been made to this domain object
|
||||
* (as well as to others that might have been retrieved and
|
||||
* modified during the editing session)
|
||||
* @param {boolean} nonrecursive if true, save only this
|
||||
* object (and not other objects with associated changes)
|
||||
* @returns {Promise} a promise that will be fulfilled after
|
||||
* persistence has completed.
|
||||
* @memberof platform/commonUI/edit.EditorCapability#
|
||||
*/
|
||||
EditorCapability.prototype.save = function (nonrecursive) {
|
||||
var domainObject = this.domainObject,
|
||||
editableObject = this.editableObject,
|
||||
cache = this.cache;
|
||||
|
||||
// Update the underlying, "real" domain object's model
|
||||
// with changes made to the copy used for editing.
|
||||
@@ -74,39 +95,32 @@ define(
|
||||
return domainObject.getCapability('persistence').persist();
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Save any changes that have been made to this domain object
|
||||
* (as well as to others that might have been retrieved and
|
||||
* modified during the editing session)
|
||||
* @param {boolean} nonrecursive if true, save only this
|
||||
* object (and not other objects with associated changes)
|
||||
* @returns {Promise} a promise that will be fulfilled after
|
||||
* persistence has completed.
|
||||
*/
|
||||
save: function (nonrecursive) {
|
||||
return nonrecursive ?
|
||||
resolvePromise(doMutate()).then(doPersist) :
|
||||
resolvePromise(cache.saveAll());
|
||||
},
|
||||
/**
|
||||
* Cancel editing; Discard any changes that have been made to
|
||||
* this domain object (as well as to others that might have
|
||||
* been retrieved and modified during the editing session)
|
||||
* @returns {Promise} a promise that will be fulfilled after
|
||||
* cancellation has completed.
|
||||
*/
|
||||
cancel: function () {
|
||||
return resolvePromise(undefined);
|
||||
},
|
||||
/**
|
||||
* Check if there are any unsaved changes.
|
||||
* @returns {boolean} true if there are unsaved changes
|
||||
*/
|
||||
dirty: function () {
|
||||
return cache.dirty();
|
||||
}
|
||||
};
|
||||
return nonrecursive ?
|
||||
resolvePromise(doMutate()).then(doPersist) :
|
||||
resolvePromise(cache.saveAll());
|
||||
};
|
||||
|
||||
/**
|
||||
* Cancel editing; Discard any changes that have been made to
|
||||
* this domain object (as well as to others that might have
|
||||
* been retrieved and modified during the editing session)
|
||||
* @returns {Promise} a promise that will be fulfilled after
|
||||
* cancellation has completed.
|
||||
* @memberof platform/commonUI/edit.EditorCapability#
|
||||
*/
|
||||
EditorCapability.prototype.cancel = function () {
|
||||
return resolvePromise(undefined);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if there are any unsaved changes.
|
||||
* @returns {boolean} true if there are unsaved changes
|
||||
* @memberof platform/commonUI/edit.EditorCapability#
|
||||
*/
|
||||
EditorCapability.prototype.dirty = function () {
|
||||
return this.cache.dirty();
|
||||
};
|
||||
|
||||
return EditorCapability;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -33,6 +33,7 @@ define(
|
||||
|
||||
/**
|
||||
* Controller which supplies action instances for Save/Cancel.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditActionController($scope) {
|
||||
@@ -51,4 +52,4 @@ define(
|
||||
|
||||
return EditActionController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining EditController. Created by vwoeltje on 11/14/14.
|
||||
* This bundle implements Edit mode.
|
||||
* @namespace platform/commonUI/edit
|
||||
*/
|
||||
define(
|
||||
["../objects/EditableDomainObject"],
|
||||
@@ -33,15 +34,16 @@ define(
|
||||
* Controller which is responsible for populating the scope for
|
||||
* Edit mode; introduces an editable version of the currently
|
||||
* navigated domain object into the scope.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditController($scope, $q, navigationService) {
|
||||
var navigatedObject;
|
||||
var self = this;
|
||||
|
||||
function setNavigation(domainObject) {
|
||||
// Wrap the domain object such that all mutation is
|
||||
// confined to edit mode (until Save)
|
||||
navigatedObject =
|
||||
self.navigatedDomainObject =
|
||||
domainObject && new EditableDomainObject(domainObject, $q);
|
||||
}
|
||||
|
||||
@@ -50,33 +52,33 @@ define(
|
||||
$scope.$on("$destroy", function () {
|
||||
navigationService.removeListener(setNavigation);
|
||||
});
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the domain object which is navigated-to.
|
||||
* @returns {DomainObject} the domain object that is navigated-to
|
||||
*/
|
||||
navigatedObject: function () {
|
||||
return navigatedObject;
|
||||
},
|
||||
/**
|
||||
* Get the warning to show if the user attempts to navigate
|
||||
* away from Edit mode while unsaved changes are present.
|
||||
* @returns {string} the warning to show, or undefined if
|
||||
* there are no unsaved changes
|
||||
*/
|
||||
getUnloadWarning: function () {
|
||||
var editorCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("editor"),
|
||||
hasChanges = editorCapability && editorCapability.dirty();
|
||||
|
||||
return hasChanges ?
|
||||
"Unsaved changes will be lost if you leave this page." :
|
||||
undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the domain object which is navigated-to.
|
||||
* @returns {DomainObject} the domain object that is navigated-to
|
||||
*/
|
||||
EditController.prototype.navigatedObject = function () {
|
||||
return this.navigatedDomainObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the warning to show if the user attempts to navigate
|
||||
* away from Edit mode while unsaved changes are present.
|
||||
* @returns {string} the warning to show, or undefined if
|
||||
* there are no unsaved changes
|
||||
*/
|
||||
EditController.prototype.getUnloadWarning = function () {
|
||||
var navigatedObject = this.navigatedDomainObject,
|
||||
editorCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("editor"),
|
||||
hasChanges = editorCapability && editorCapability.dirty();
|
||||
|
||||
return hasChanges ?
|
||||
"Unsaved changes will be lost if you leave this page." :
|
||||
undefined;
|
||||
};
|
||||
|
||||
return EditController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -28,15 +28,17 @@ define(
|
||||
|
||||
/**
|
||||
* Supports the Library and Elements panes in Edit mode.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditPanesController($scope) {
|
||||
var root;
|
||||
var self = this;
|
||||
|
||||
// Update root object based on represented object
|
||||
function updateRoot(domainObject) {
|
||||
var context = domainObject &&
|
||||
domainObject.getCapability('context'),
|
||||
var root = self.rootDomainObject,
|
||||
context = domainObject &&
|
||||
domainObject.getCapability('context'),
|
||||
newRoot = context && context.getTrueRoot(),
|
||||
oldId = root && root.getId(),
|
||||
newId = newRoot && newRoot.getId();
|
||||
@@ -44,25 +46,22 @@ define(
|
||||
// Only update if this has actually changed,
|
||||
// to avoid excessive refreshing.
|
||||
if (oldId !== newId) {
|
||||
root = newRoot;
|
||||
self.rootDomainObject = newRoot;
|
||||
}
|
||||
}
|
||||
|
||||
// Update root when represented object changes
|
||||
$scope.$watch('domainObject', updateRoot);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the root-level domain object, as reported by the
|
||||
* represented domain object.
|
||||
* @returns {DomainObject} the root object
|
||||
*/
|
||||
getRoot: function () {
|
||||
return root;
|
||||
}
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Get the root-level domain object, as reported by the
|
||||
* represented domain object.
|
||||
* @returns {DomainObject} the root object
|
||||
*/
|
||||
EditPanesController.prototype.getRoot = function () {
|
||||
return this.rootDomainObject;
|
||||
};
|
||||
|
||||
return EditPanesController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -31,6 +31,7 @@ define(
|
||||
* to this attribute will be evaluated during page navigation events
|
||||
* and, if it returns a truthy value, will be used to populate a
|
||||
* prompt to the user to confirm this navigation.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @param $window the window
|
||||
*/
|
||||
@@ -102,4 +103,4 @@ define(
|
||||
return MCTBeforeUnload;
|
||||
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -68,6 +68,9 @@ define(
|
||||
* which need to behave differently in edit mode,
|
||||
* and provides a "working copy" of the object's
|
||||
* model to allow changes to be easily cancelled.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {DomainObject}
|
||||
*/
|
||||
function EditableDomainObject(domainObject, $q) {
|
||||
// The cache will hold all domain objects reached from
|
||||
@@ -92,10 +95,10 @@ define(
|
||||
this,
|
||||
delegateArguments
|
||||
),
|
||||
factory = capabilityFactories[name];
|
||||
Factory = capabilityFactories[name];
|
||||
|
||||
return (factory && capability) ?
|
||||
factory(capability, editableObject, domainObject, cache) :
|
||||
return (Factory && capability) ?
|
||||
new Factory(capability, editableObject, domainObject, cache) :
|
||||
capability;
|
||||
};
|
||||
|
||||
@@ -109,4 +112,4 @@ define(
|
||||
|
||||
return EditableDomainObject;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
/*global define*/
|
||||
|
||||
|
||||
/**
|
||||
/*
|
||||
* An editable domain object cache stores domain objects that have been
|
||||
* made editable, in a group that can be saved all-at-once. This supports
|
||||
* Edit mode, which is launched for a specific object but may contain
|
||||
@@ -32,8 +32,6 @@
|
||||
* to ensure that changes made while in edit mode do not propagate up
|
||||
* to the objects used in browse mode (or to persistence) until the user
|
||||
* initiates a Save.
|
||||
*
|
||||
* @module editor/object/editable-domain-object-cache
|
||||
*/
|
||||
define(
|
||||
["./EditableModelCache"],
|
||||
@@ -46,107 +44,118 @@ define(
|
||||
* of objects retrieved via composition or context capabilities as
|
||||
* editable domain objects.
|
||||
*
|
||||
* @param {Constructor<EditableDomainObject>} EditableDomainObject a
|
||||
* @param {Constructor<DomainObject>} EditableDomainObject a
|
||||
* constructor function which takes a regular domain object as
|
||||
* an argument, and returns an editable domain object as its
|
||||
* result.
|
||||
* @param $q Angular's $q, for promise handling
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @memberof module:editor/object/editable-domain-object-cache
|
||||
*/
|
||||
function EditableDomainObjectCache(EditableDomainObject, $q) {
|
||||
var cache = new EditableModelCache(),
|
||||
dirty = {},
|
||||
root;
|
||||
|
||||
return {
|
||||
/**
|
||||
* Wrap this domain object in an editable form, or pull such
|
||||
* an object from the cache if one already exists.
|
||||
*
|
||||
* @param {DomainObject} domainObject the regular domain object
|
||||
* @returns {DomainObject} the domain object in an editable form
|
||||
*/
|
||||
getEditableObject: function (domainObject) {
|
||||
var type = domainObject.getCapability('type');
|
||||
|
||||
// Track the top-level domain object; this will have
|
||||
// some special behavior for its context capability.
|
||||
root = root || domainObject;
|
||||
|
||||
// Avoid double-wrapping (WTD-1017)
|
||||
if (domainObject.hasCapability('editor')) {
|
||||
return domainObject;
|
||||
}
|
||||
|
||||
// Don't bother wrapping non-editable objects
|
||||
if (!type || !type.hasFeature('creation')) {
|
||||
return domainObject;
|
||||
}
|
||||
|
||||
// Provide an editable form of the object
|
||||
return new EditableDomainObject(
|
||||
domainObject,
|
||||
cache.getCachedModel(domainObject)
|
||||
);
|
||||
},
|
||||
/**
|
||||
* Check if a domain object is (effectively) the top-level
|
||||
* object in this editable subgraph.
|
||||
* @returns {boolean} true if it is the root
|
||||
*/
|
||||
isRoot: function (domainObject) {
|
||||
return domainObject === root;
|
||||
},
|
||||
/**
|
||||
* Mark an editable domain object (presumably already cached)
|
||||
* as having received modifications during editing; it should be
|
||||
* included in the bulk save invoked when editing completes.
|
||||
*
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
*/
|
||||
markDirty: function (domainObject) {
|
||||
dirty[domainObject.getId()] = domainObject;
|
||||
},
|
||||
/**
|
||||
* Mark an object (presumably already cached) as having had its
|
||||
* changes saved (and thus no longer needing to be subject to a
|
||||
* save operation.)
|
||||
*
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
*/
|
||||
markClean: function (domainObject) {
|
||||
delete dirty[domainObject.getId()];
|
||||
},
|
||||
/**
|
||||
* Initiate a save on all objects that have been cached.
|
||||
*/
|
||||
saveAll: function () {
|
||||
// Get a list of all dirty objects
|
||||
var objects = Object.keys(dirty).map(function (k) {
|
||||
return dirty[k];
|
||||
});
|
||||
|
||||
// Clear dirty set, since we're about to save.
|
||||
dirty = {};
|
||||
|
||||
// Most save logic is handled by the "editor.completion"
|
||||
// capability, so that is delegated here.
|
||||
return $q.all(objects.map(function (object) {
|
||||
// Save; pass a nonrecursive flag to avoid looping
|
||||
return object.getCapability('editor').save(true);
|
||||
}));
|
||||
},
|
||||
/**
|
||||
* Check if any objects have been marked dirty in this cache.
|
||||
* @returns {boolean} true if objects are dirty
|
||||
*/
|
||||
dirty: function () {
|
||||
return Object.keys(dirty).length > 0;
|
||||
}
|
||||
};
|
||||
this.cache = new EditableModelCache();
|
||||
this.dirtyObjects = {};
|
||||
this.root = undefined;
|
||||
this.$q = $q;
|
||||
this.EditableDomainObject = EditableDomainObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap this domain object in an editable form, or pull such
|
||||
* an object from the cache if one already exists.
|
||||
*
|
||||
* @param {DomainObject} domainObject the regular domain object
|
||||
* @returns {DomainObject} the domain object in an editable form
|
||||
*/
|
||||
EditableDomainObjectCache.prototype.getEditableObject = function (domainObject) {
|
||||
var type = domainObject.getCapability('type'),
|
||||
EditableDomainObject = this.EditableDomainObject;
|
||||
|
||||
// Track the top-level domain object; this will have
|
||||
// some special behavior for its context capability.
|
||||
this.root = this.root || domainObject;
|
||||
|
||||
// Avoid double-wrapping (WTD-1017)
|
||||
if (domainObject.hasCapability('editor')) {
|
||||
return domainObject;
|
||||
}
|
||||
|
||||
// Don't bother wrapping non-editable objects
|
||||
if (!type || !type.hasFeature('creation')) {
|
||||
return domainObject;
|
||||
}
|
||||
|
||||
// Provide an editable form of the object
|
||||
return new EditableDomainObject(
|
||||
domainObject,
|
||||
this.cache.getCachedModel(domainObject)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if a domain object is (effectively) the top-level
|
||||
* object in this editable subgraph.
|
||||
* @returns {boolean} true if it is the root
|
||||
*/
|
||||
EditableDomainObjectCache.prototype.isRoot = function (domainObject) {
|
||||
return domainObject === this.root;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mark an editable domain object (presumably already cached)
|
||||
* as having received modifications during editing; it should be
|
||||
* included in the bulk save invoked when editing completes.
|
||||
*
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* @memberof platform/commonUI/edit.EditableDomainObjectCache#
|
||||
*/
|
||||
EditableDomainObjectCache.prototype.markDirty = function (domainObject) {
|
||||
this.dirtyObjects[domainObject.getId()] = domainObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mark an object (presumably already cached) as having had its
|
||||
* changes saved (and thus no longer needing to be subject to a
|
||||
* save operation.)
|
||||
*
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
*/
|
||||
EditableDomainObjectCache.prototype.markClean = function (domainObject) {
|
||||
delete this.dirtyObjects[domainObject.getId()];
|
||||
};
|
||||
|
||||
/**
|
||||
* Initiate a save on all objects that have been cached.
|
||||
* @return {Promise} A promise which will resolve when all objects are
|
||||
* persisted.
|
||||
*/
|
||||
EditableDomainObjectCache.prototype.saveAll = function () {
|
||||
// Get a list of all dirty objects
|
||||
var dirty = this.dirtyObjects,
|
||||
objects = Object.keys(dirty).map(function (k) {
|
||||
return dirty[k];
|
||||
});
|
||||
|
||||
// Clear dirty set, since we're about to save.
|
||||
this.dirtyObjects = {};
|
||||
|
||||
// Most save logic is handled by the "editor.completion"
|
||||
// capability, so that is delegated here.
|
||||
return this.$q.all(objects.map(function (object) {
|
||||
// Save; pass a nonrecursive flag to avoid looping
|
||||
return object.getCapability('editor').save(true);
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if any objects have been marked dirty in this cache.
|
||||
* @returns {boolean} true if objects are dirty
|
||||
*/
|
||||
EditableDomainObjectCache.prototype.dirty = function () {
|
||||
return Object.keys(this.dirtyObjects).length > 0;
|
||||
};
|
||||
|
||||
return EditableDomainObjectCache;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -31,33 +31,32 @@ define(
|
||||
* made editable, to support a group that can be saved all-at-once.
|
||||
* This is useful in Edit mode, which is launched for a specific
|
||||
* object but may contain changes across many objects.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditableModelCache() {
|
||||
var cache = {};
|
||||
|
||||
// Deep-copy a model. Models are JSONifiable, so this can be
|
||||
// done by stringification then destringification
|
||||
function clone(model) {
|
||||
return JSON.parse(JSON.stringify(model));
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get this domain object's model from the cache (or
|
||||
* place it in the cache if it isn't in the cache yet)
|
||||
* @returns a clone of the domain object's model
|
||||
*/
|
||||
getCachedModel: function (domainObject) {
|
||||
var id = domainObject.getId();
|
||||
|
||||
return (cache[id] =
|
||||
cache[id] || clone(domainObject.getModel()));
|
||||
}
|
||||
};
|
||||
|
||||
this.cache = {};
|
||||
}
|
||||
|
||||
// Deep-copy a model. Models are JSONifiable, so this can be
|
||||
// done by stringification then destringification
|
||||
function clone(model) {
|
||||
return JSON.parse(JSON.stringify(model));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this domain object's model from the cache (or
|
||||
* place it in the cache if it isn't in the cache yet)
|
||||
* @returns a clone of the domain object's model
|
||||
*/
|
||||
EditableModelCache.prototype.getCachedModel = function (domainObject) {
|
||||
var id = domainObject.getId(),
|
||||
cache = this.cache;
|
||||
|
||||
return (cache[id] =
|
||||
cache[id] || clone(domainObject.getModel()));
|
||||
};
|
||||
|
||||
return EditableModelCache;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -30,53 +30,47 @@ define(
|
||||
* Policy controlling when the `edit` and/or `properties` actions
|
||||
* can appear as applicable actions of the `view-control` category
|
||||
* (shown as buttons in the top-right of browse mode.)
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @implements {Policy.<Action, ActionContext>}
|
||||
*/
|
||||
function EditActionPolicy() {
|
||||
// Get a count of views which are not flagged as non-editable.
|
||||
function countEditableViews(context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
views = domainObject && domainObject.useCapability('view'),
|
||||
count = 0;
|
||||
}
|
||||
|
||||
// A view is editable unless explicitly flagged as not
|
||||
(views || []).forEach(function (view) {
|
||||
count += (view.editable !== false) ? 1 : 0;
|
||||
});
|
||||
// Get a count of views which are not flagged as non-editable.
|
||||
function countEditableViews(context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
views = domainObject && domainObject.useCapability('view'),
|
||||
count = 0;
|
||||
|
||||
return count;
|
||||
// A view is editable unless explicitly flagged as not
|
||||
(views || []).forEach(function (view) {
|
||||
count += (view.editable !== false) ? 1 : 0;
|
||||
});
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
EditActionPolicy.prototype.allow = function (action, context) {
|
||||
var key = action.getMetadata().key,
|
||||
category = (context || {}).category;
|
||||
|
||||
// Only worry about actions in the view-control category
|
||||
if (category === 'view-control') {
|
||||
// Restrict 'edit' to cases where there are editable
|
||||
// views (similarly, restrict 'properties' to when
|
||||
// the converse is true)
|
||||
if (key === 'edit') {
|
||||
return countEditableViews(context) > 0;
|
||||
} else if (key === 'properties') {
|
||||
return countEditableViews(context) < 1;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Check whether or not a given action is allowed by this
|
||||
* policy.
|
||||
* @param {Action} action the action
|
||||
* @param context the context
|
||||
* @returns {boolean} true if not disallowed
|
||||
*/
|
||||
allow: function (action, context) {
|
||||
var key = action.getMetadata().key,
|
||||
category = (context || {}).category;
|
||||
|
||||
// Only worry about actions in the view-control category
|
||||
if (category === 'view-control') {
|
||||
// Restrict 'edit' to cases where there are editable
|
||||
// views (similarly, restrict 'properties' to when
|
||||
// the converse is true)
|
||||
if (key === 'edit') {
|
||||
return countEditableViews(context) > 0;
|
||||
} else if (key === 'properties') {
|
||||
return countEditableViews(context) < 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
// Like all policies, allow by default.
|
||||
return true;
|
||||
};
|
||||
|
||||
return EditActionPolicy;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -28,30 +28,24 @@ define(
|
||||
|
||||
/**
|
||||
* Policy controlling which views should be visible in Edit mode.
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @implements {Policy.<View, DomainObject>}
|
||||
*/
|
||||
function EditableViewPolicy() {
|
||||
return {
|
||||
/**
|
||||
* Check whether or not a given action is allowed by this
|
||||
* policy.
|
||||
* @param {Action} action the action
|
||||
* @param domainObject the domain object which will be viewed
|
||||
* @returns {boolean} true if not disallowed
|
||||
*/
|
||||
allow: function (view, domainObject) {
|
||||
// If a view is flagged as non-editable, only allow it
|
||||
// while we're not in Edit mode.
|
||||
if ((view || {}).editable === false) {
|
||||
return !domainObject.hasCapability('editor');
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
EditableViewPolicy.prototype.allow = function (view, domainObject) {
|
||||
// If a view is flagged as non-editable, only allow it
|
||||
// while we're not in Edit mode.
|
||||
if ((view || {}).editable === false) {
|
||||
return !domainObject.hasCapability('editor');
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
return true;
|
||||
};
|
||||
|
||||
return EditableViewPolicy;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -41,14 +41,17 @@ define(
|
||||
* and may be reused for different domain objects and/or
|
||||
* representations resulting from changes there.
|
||||
*
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Representer}
|
||||
* @constructor
|
||||
*/
|
||||
function EditRepresenter($q, $log, scope) {
|
||||
var domainObject,
|
||||
key;
|
||||
var self = this;
|
||||
|
||||
// Mutate and persist a new version of a domain object's model.
|
||||
function doPersist(model) {
|
||||
var domainObject = self.domainObject;
|
||||
|
||||
// First, mutate; then, persist.
|
||||
return $q.when(domainObject.useCapability("mutation", function () {
|
||||
return model;
|
||||
@@ -64,7 +67,8 @@ define(
|
||||
// Look up from scope; these will have been populated by
|
||||
// mct-representation.
|
||||
var model = scope.model,
|
||||
configuration = scope.configuration;
|
||||
configuration = scope.configuration,
|
||||
domainObject = self.domainObject;
|
||||
|
||||
// Log the commit message
|
||||
$log.debug([
|
||||
@@ -78,50 +82,33 @@ define(
|
||||
if (domainObject && domainObject.hasCapability("persistence")) {
|
||||
// Configurations for specific views are stored by
|
||||
// key in the "configuration" field of the model.
|
||||
if (key && configuration) {
|
||||
if (self.key && configuration) {
|
||||
model.configuration = model.configuration || {};
|
||||
model.configuration[key] = configuration;
|
||||
model.configuration[self.key] = configuration;
|
||||
}
|
||||
doPersist(model);
|
||||
}
|
||||
}
|
||||
|
||||
// Respond to the destruction of the current representation.
|
||||
function destroy() {
|
||||
// Nothing to clean up
|
||||
}
|
||||
|
||||
// Handle a specific representation of a specific domain object
|
||||
function represent(representation, representedObject) {
|
||||
// Track the key, to know which view configuration to save to.
|
||||
key = (representation || {}).key;
|
||||
// Track the represented object
|
||||
domainObject = representedObject;
|
||||
// Ensure existing watches are released
|
||||
destroy();
|
||||
}
|
||||
|
||||
// Place the "commit" method in the scope
|
||||
scope.commit = commit;
|
||||
|
||||
return {
|
||||
/**
|
||||
* Set the current representation in use, and the domain
|
||||
* object being represented.
|
||||
*
|
||||
* @param {RepresentationDefinition} representation the
|
||||
* definition of the representation in use
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* being represented
|
||||
*/
|
||||
represent: represent,
|
||||
/**
|
||||
* Release any resources associated with this representer.
|
||||
*/
|
||||
destroy: destroy
|
||||
};
|
||||
}
|
||||
|
||||
// Handle a specific representation of a specific domain object
|
||||
EditRepresenter.prototype.represent = function represent(representation, representedObject) {
|
||||
// Track the key, to know which view configuration to save to.
|
||||
this.key = (representation || {}).key;
|
||||
// Track the represented object
|
||||
this.domainObject = representedObject;
|
||||
// Ensure existing watches are released
|
||||
this.destroy();
|
||||
};
|
||||
|
||||
// Respond to the destruction of the current representation.
|
||||
EditRepresenter.prototype.destroy = function destroy() {
|
||||
// Nothing to clean up
|
||||
};
|
||||
|
||||
return EditRepresenter;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -38,125 +38,23 @@ define(
|
||||
*
|
||||
* @param structure toolbar structure, as provided by view definition
|
||||
* @param {Function} commit callback to invoke after changes
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditToolbar(structure, commit) {
|
||||
var toolbarStructure = Object.create(structure || {}),
|
||||
toolbarState,
|
||||
selection,
|
||||
properties = [];
|
||||
var self = this;
|
||||
|
||||
// Generate a new key for an item's property
|
||||
function addKey(property) {
|
||||
properties.push(property);
|
||||
return properties.length - 1; // Return index of property
|
||||
}
|
||||
|
||||
// Update value for this property in all elements of the
|
||||
// selection which have this property.
|
||||
function updateProperties(property, value) {
|
||||
var changed = false;
|
||||
|
||||
// Update property in a selected element
|
||||
function updateProperty(selected) {
|
||||
// Ignore selected elements which don't have this property
|
||||
if (selected[property] !== undefined) {
|
||||
// Check if this is a setter, or just assignable
|
||||
if (typeof selected[property] === 'function') {
|
||||
changed =
|
||||
changed || (selected[property]() !== value);
|
||||
selected[property](value);
|
||||
} else {
|
||||
changed =
|
||||
changed || (selected[property] !== value);
|
||||
selected[property] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update property in all selected elements
|
||||
selection.forEach(updateProperty);
|
||||
|
||||
// Return whether or not anything changed
|
||||
return changed;
|
||||
}
|
||||
|
||||
// Look up the current value associated with a property
|
||||
// in selection i
|
||||
function lookupState(property, selected) {
|
||||
var value = selected[property];
|
||||
return (typeof value === 'function') ? value() : value;
|
||||
}
|
||||
|
||||
// Get initial value for a given property
|
||||
function initializeState(property) {
|
||||
var result;
|
||||
// Look through all selections for this property;
|
||||
// values should all match by the time we perform
|
||||
// this lookup anyway.
|
||||
selection.forEach(function (selected) {
|
||||
result = (selected[property] !== undefined) ?
|
||||
lookupState(property, selected) :
|
||||
result;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check if all elements of the selection which have this
|
||||
// property have the same value for this property.
|
||||
function isConsistent(property) {
|
||||
var consistent = true,
|
||||
observed = false,
|
||||
state;
|
||||
|
||||
// Check if a given element of the selection is consistent
|
||||
// with previously-observed elements for this property.
|
||||
function checkConsistency(selected) {
|
||||
var next;
|
||||
// Ignore selections which don't have this property
|
||||
if (selected[property] !== undefined) {
|
||||
// Look up state of this element in the selection
|
||||
next = lookupState(property, selected);
|
||||
// Detect inconsistency
|
||||
if (observed) {
|
||||
consistent = consistent && (next === state);
|
||||
}
|
||||
// Track state for next iteration
|
||||
state = next;
|
||||
observed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through selections
|
||||
selection.forEach(checkConsistency);
|
||||
|
||||
return consistent;
|
||||
}
|
||||
|
||||
// Used to filter out items which are applicable (or not)
|
||||
// to the current selection.
|
||||
function isApplicable(item) {
|
||||
var property = (item || {}).property,
|
||||
method = (item || {}).method,
|
||||
exclusive = !!(item || {}).exclusive;
|
||||
|
||||
// Check if a selected item defines this property
|
||||
function hasProperty(selected) {
|
||||
return (property && (selected[property] !== undefined)) ||
|
||||
(method && (typeof selected[method] === 'function'));
|
||||
}
|
||||
|
||||
return selection.map(hasProperty).reduce(
|
||||
exclusive ? and : or,
|
||||
exclusive
|
||||
) && isConsistent(property);
|
||||
self.properties.push(property);
|
||||
return self.properties.length - 1; // Return index of property
|
||||
}
|
||||
|
||||
// Invoke all functions in selections with the given name
|
||||
function invoke(method, value) {
|
||||
if (method) {
|
||||
// Make the change in the selection
|
||||
selection.forEach(function (selected) {
|
||||
self.selection.forEach(function (selected) {
|
||||
if (typeof selected[method] === 'function') {
|
||||
selected[method](value);
|
||||
}
|
||||
@@ -189,73 +87,172 @@ define(
|
||||
return converted;
|
||||
}
|
||||
|
||||
this.toolbarState = [];
|
||||
this.selection = undefined;
|
||||
this.properties = [];
|
||||
this.toolbarStructure = Object.create(structure || {});
|
||||
this.toolbarStructure.sections =
|
||||
((structure || {}).sections || []).map(convertSection);
|
||||
}
|
||||
|
||||
// Check if all elements of the selection which have this
|
||||
// property have the same value for this property.
|
||||
EditToolbar.prototype.isConsistent = function (property) {
|
||||
var self = this,
|
||||
consistent = true,
|
||||
observed = false,
|
||||
state;
|
||||
|
||||
// Check if a given element of the selection is consistent
|
||||
// with previously-observed elements for this property.
|
||||
function checkConsistency(selected) {
|
||||
var next;
|
||||
// Ignore selections which don't have this property
|
||||
if (selected[property] !== undefined) {
|
||||
// Look up state of this element in the selection
|
||||
next = self.lookupState(property, selected);
|
||||
// Detect inconsistency
|
||||
if (observed) {
|
||||
consistent = consistent && (next === state);
|
||||
}
|
||||
// Track state for next iteration
|
||||
state = next;
|
||||
observed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through selections
|
||||
self.selection.forEach(checkConsistency);
|
||||
|
||||
return consistent;
|
||||
};
|
||||
|
||||
// Used to filter out items which are applicable (or not)
|
||||
// to the current selection.
|
||||
EditToolbar.prototype.isApplicable = function (item) {
|
||||
var property = (item || {}).property,
|
||||
method = (item || {}).method,
|
||||
exclusive = !!(item || {}).exclusive;
|
||||
|
||||
// Check if a selected item defines this property
|
||||
function hasProperty(selected) {
|
||||
return (property && (selected[property] !== undefined)) ||
|
||||
(method && (typeof selected[method] === 'function'));
|
||||
}
|
||||
|
||||
return this.selection.map(hasProperty).reduce(
|
||||
exclusive ? and : or,
|
||||
exclusive
|
||||
) && this.isConsistent(property);
|
||||
};
|
||||
|
||||
|
||||
// Look up the current value associated with a property
|
||||
EditToolbar.prototype.lookupState = function (property, selected) {
|
||||
var value = selected[property];
|
||||
return (typeof value === 'function') ? value() : value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the current selection. Visibility of sections
|
||||
* and items in the toolbar will be updated to match this.
|
||||
* @param {Array} s the new selection
|
||||
*/
|
||||
EditToolbar.prototype.setSelection = function (s) {
|
||||
var self = this;
|
||||
|
||||
// Show/hide controls in this section per applicability
|
||||
function refreshSectionApplicability(section) {
|
||||
var count = 0;
|
||||
// Show/hide each item
|
||||
(section.items || []).forEach(function (item) {
|
||||
item.hidden = !isApplicable(item);
|
||||
item.hidden = !self.isApplicable(item);
|
||||
count += item.hidden ? 0 : 1;
|
||||
});
|
||||
// Hide this section if there are no applicable items
|
||||
section.hidden = !count;
|
||||
}
|
||||
|
||||
// Show/hide controls if they are applicable
|
||||
function refreshApplicability() {
|
||||
toolbarStructure.sections.forEach(refreshSectionApplicability);
|
||||
// Get initial value for a given property
|
||||
function initializeState(property) {
|
||||
var result;
|
||||
// Look through all selections for this property;
|
||||
// values should all match by the time we perform
|
||||
// this lookup anyway.
|
||||
self.selection.forEach(function (selected) {
|
||||
result = (selected[property] !== undefined) ?
|
||||
self.lookupState(property, selected) :
|
||||
result;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// Refresh toolbar state to match selection
|
||||
function refreshState() {
|
||||
toolbarState = properties.map(initializeState);
|
||||
}
|
||||
this.selection = s;
|
||||
this.toolbarStructure.sections.forEach(refreshSectionApplicability);
|
||||
this.toolbarState = this.properties.map(initializeState);
|
||||
};
|
||||
|
||||
toolbarStructure.sections =
|
||||
((structure || {}).sections || []).map(convertSection);
|
||||
/**
|
||||
* Get the structure of the toolbar, as appropriate to
|
||||
* pass to `mct-toolbar`.
|
||||
* @returns the toolbar structure
|
||||
*/
|
||||
EditToolbar.prototype.getStructure = function () {
|
||||
return this.toolbarStructure;
|
||||
};
|
||||
|
||||
toolbarState = [];
|
||||
/**
|
||||
* Get the current state of the toolbar, as appropriate
|
||||
* to two-way bind to the state handled by `mct-toolbar`.
|
||||
* @returns {Array} state of the toolbar
|
||||
*/
|
||||
EditToolbar.prototype.getState = function () {
|
||||
return this.toolbarState;
|
||||
};
|
||||
|
||||
return {
|
||||
/**
|
||||
* Set the current selection. Visisbility of sections
|
||||
* and items in the toolbar will be updated to match this.
|
||||
* @param {Array} s the new selection
|
||||
*/
|
||||
setSelection: function (s) {
|
||||
selection = s;
|
||||
refreshApplicability();
|
||||
refreshState();
|
||||
},
|
||||
/**
|
||||
* Get the structure of the toolbar, as appropriate to
|
||||
* pass to `mct-toolbar`.
|
||||
* @returns the toolbar structure
|
||||
*/
|
||||
getStructure: function () {
|
||||
return toolbarStructure;
|
||||
},
|
||||
/**
|
||||
* Get the current state of the toolbar, as appropriate
|
||||
* to two-way bind to the state handled by `mct-toolbar`.
|
||||
* @returns {Array} state of the toolbar
|
||||
*/
|
||||
getState: function () {
|
||||
return toolbarState;
|
||||
},
|
||||
/**
|
||||
* Update state within the current selection.
|
||||
* @param {number} index the index of the corresponding
|
||||
* element in the state array
|
||||
* @param value the new value to convey to the selection
|
||||
*/
|
||||
updateState: function (index, value) {
|
||||
return updateProperties(properties[index], value);
|
||||
/**
|
||||
* Update state within the current selection.
|
||||
* @param {number} index the index of the corresponding
|
||||
* element in the state array
|
||||
* @param value the new value to convey to the selection
|
||||
*/
|
||||
EditToolbar.prototype.updateState = function (index, value) {
|
||||
var self = this;
|
||||
|
||||
// Update value for this property in all elements of the
|
||||
// selection which have this property.
|
||||
function updateProperties(property, value) {
|
||||
var changed = false;
|
||||
|
||||
// Update property in a selected element
|
||||
function updateProperty(selected) {
|
||||
// Ignore selected elements which don't have this property
|
||||
if (selected[property] !== undefined) {
|
||||
// Check if this is a setter, or just assignable
|
||||
if (typeof selected[property] === 'function') {
|
||||
changed =
|
||||
changed || (selected[property]() !== value);
|
||||
selected[property](value);
|
||||
} else {
|
||||
changed =
|
||||
changed || (selected[property] !== value);
|
||||
selected[property] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Update property in all selected elements
|
||||
self.selection.forEach(updateProperty);
|
||||
|
||||
// Return whether or not anything changed
|
||||
return changed;
|
||||
}
|
||||
|
||||
return updateProperties(this.properties[index], value);
|
||||
};
|
||||
|
||||
return EditToolbar;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -27,17 +27,21 @@ define(
|
||||
"use strict";
|
||||
|
||||
// No operation
|
||||
function noop() {}
|
||||
var NOOP_REPRESENTER = {
|
||||
represent: function () {},
|
||||
destroy: function () {}
|
||||
};
|
||||
|
||||
/**
|
||||
* The EditToolbarRepresenter populates the toolbar in Edit mode
|
||||
* based on a view's definition.
|
||||
* @param {Scope} scope the Angular scope of the representation
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
* @implements {Representer}
|
||||
*/
|
||||
function EditToolbarRepresenter(scope, element, attrs) {
|
||||
var toolbar,
|
||||
toolbarObject = {};
|
||||
var self = this;
|
||||
|
||||
// Mark changes as ready to persist
|
||||
function commit(message) {
|
||||
@@ -49,31 +53,33 @@ define(
|
||||
// Handle changes to the current selection
|
||||
function updateSelection(selection) {
|
||||
// Only update if there is a toolbar to update
|
||||
if (toolbar) {
|
||||
if (self.toolbar) {
|
||||
// Make sure selection is array-like
|
||||
selection = Array.isArray(selection) ?
|
||||
selection :
|
||||
(selection ? [selection] : []);
|
||||
|
||||
// Update the toolbar's selection
|
||||
toolbar.setSelection(selection);
|
||||
self.toolbar.setSelection(selection);
|
||||
|
||||
// ...and expose its structure/state
|
||||
toolbarObject.structure = toolbar.getStructure();
|
||||
toolbarObject.state = toolbar.getState();
|
||||
self.toolbarObject.structure =
|
||||
self.toolbar.getStructure();
|
||||
self.toolbarObject.state =
|
||||
self.toolbar.getState();
|
||||
}
|
||||
}
|
||||
|
||||
// Get state (to watch it)
|
||||
function getState() {
|
||||
return toolbarObject.state;
|
||||
return self.toolbarObject.state;
|
||||
}
|
||||
|
||||
// Update selection models to match changed toolbar state
|
||||
function updateState(state) {
|
||||
// Update underlying state based on toolbar changes
|
||||
var changed = (state || []).map(function (value, index) {
|
||||
return toolbar.updateState(index, value);
|
||||
return self.toolbar.updateState(index, value);
|
||||
}).reduce(function (a, b) {
|
||||
return a || b;
|
||||
}, false);
|
||||
@@ -85,66 +91,73 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize toolbar (expose object to parent scope)
|
||||
function initialize(definition) {
|
||||
// If we have been asked to expose toolbar state...
|
||||
if (attrs.toolbar) {
|
||||
// Initialize toolbar object
|
||||
toolbar = new EditToolbar(definition, commit);
|
||||
// Ensure toolbar state is exposed
|
||||
scope.$parent[attrs.toolbar] = toolbarObject;
|
||||
}
|
||||
}
|
||||
|
||||
// Represent a domain object using this definition
|
||||
function represent(representation) {
|
||||
// Get the newest toolbar definition from the view
|
||||
var definition = (representation || {}).toolbar || {};
|
||||
// Expose the toolbar object to the parent scope
|
||||
initialize(definition);
|
||||
// Create a selection scope
|
||||
scope.selection = new EditToolbarSelection();
|
||||
// Initialize toolbar to an empty selection
|
||||
updateSelection([]);
|
||||
}
|
||||
|
||||
// Destroy; remove toolbar object from parent scope
|
||||
function destroy() {
|
||||
// Avoid attaching scope to this;
|
||||
// http://errors.angularjs.org/1.2.26/ng/cpws
|
||||
this.setSelection = function (s) {
|
||||
scope.selection = s;
|
||||
};
|
||||
this.clearExposedToolbar = function () {
|
||||
// Clear exposed toolbar state (if any)
|
||||
if (attrs.toolbar) {
|
||||
delete scope.$parent[attrs.toolbar];
|
||||
}
|
||||
}
|
||||
};
|
||||
this.exposeToolbar = function () {
|
||||
scope.$parent[self.attrs.toolbar] = self.toolbarObject;
|
||||
};
|
||||
|
||||
this.commit = commit;
|
||||
this.attrs = attrs;
|
||||
this.updateSelection = updateSelection;
|
||||
this.toolbar = undefined;
|
||||
this.toolbarObject = {};
|
||||
|
||||
// If this representation exposes a toolbar, set up watches
|
||||
// to synchronize with it.
|
||||
if (attrs.toolbar) {
|
||||
if (attrs && attrs.toolbar) {
|
||||
// Detect and handle changes to state from the toolbar
|
||||
scope.$watchCollection(getState, updateState);
|
||||
// Watch for changes in the current selection state
|
||||
scope.$watchCollection("selection.all()", updateSelection);
|
||||
// Expose toolbar state under that name
|
||||
scope.$parent[attrs.toolbar] = toolbarObject;
|
||||
scope.$parent[attrs.toolbar] = this.toolbarObject;
|
||||
} else {
|
||||
// No toolbar declared, so do nothing.
|
||||
return NOOP_REPRESENTER;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Set the current representation in use, and the domain
|
||||
* object being represented.
|
||||
*
|
||||
* @param {RepresentationDefinition} representation the
|
||||
* definition of the representation in use
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* being represented
|
||||
*/
|
||||
represent: (attrs || {}).toolbar ? represent : noop,
|
||||
/**
|
||||
* Release any resources associated with this representer.
|
||||
*/
|
||||
destroy: (attrs || {}).toolbar ? destroy : noop
|
||||
};
|
||||
}
|
||||
|
||||
// Represent a domain object using this definition
|
||||
EditToolbarRepresenter.prototype.represent = function (representation) {
|
||||
// Get the newest toolbar definition from the view
|
||||
var definition = (representation || {}).toolbar || {},
|
||||
self = this;
|
||||
|
||||
// Initialize toolbar (expose object to parent scope)
|
||||
function initialize(definition) {
|
||||
// If we have been asked to expose toolbar state...
|
||||
if (self.attrs.toolbar) {
|
||||
// Initialize toolbar object
|
||||
self.toolbar = new EditToolbar(definition, self.commit);
|
||||
// Ensure toolbar state is exposed
|
||||
self.exposeToolbar();
|
||||
}
|
||||
}
|
||||
|
||||
// Expose the toolbar object to the parent scope
|
||||
initialize(definition);
|
||||
// Create a selection scope
|
||||
this.setSelection(new EditToolbarSelection());
|
||||
// Initialize toolbar to an empty selection
|
||||
this.updateSelection([]);
|
||||
};
|
||||
|
||||
// Destroy; remove toolbar object from parent scope
|
||||
EditToolbarRepresenter.prototype.destroy = function () {
|
||||
this.clearExposedToolbar();
|
||||
};
|
||||
|
||||
return EditToolbarRepresenter;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -37,110 +37,96 @@ define(
|
||||
* * The selection, for single selected elements within the
|
||||
* view.
|
||||
*
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditToolbarSelection() {
|
||||
var selection = [ {} ],
|
||||
selecting = false,
|
||||
selected;
|
||||
this.selection = [{}];
|
||||
this.selecting = false;
|
||||
this.selectedObj = undefined;
|
||||
}
|
||||
|
||||
// Remove the currently-selected object
|
||||
function deselect() {
|
||||
// Nothing to do if we don't have a selected object
|
||||
if (selecting) {
|
||||
// Clear state tracking
|
||||
selecting = false;
|
||||
selected = undefined;
|
||||
/**
|
||||
* Check if an object is currently selected.
|
||||
* @param {*} obj the object to check for selection
|
||||
* @returns {boolean} true if selected, otherwise false
|
||||
*/
|
||||
EditToolbarSelection.prototype.selected = function (obj) {
|
||||
return (obj === this.selectedObj) || (obj === this.selection[0]);
|
||||
};
|
||||
|
||||
// Remove the selection
|
||||
selection.pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Select an object.
|
||||
* @param obj the object to select
|
||||
* @returns {boolean} true if selection changed
|
||||
*/
|
||||
EditToolbarSelection.prototype.select = function (obj) {
|
||||
// Proxy is always selected
|
||||
if (obj === this.selection[0]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select an object
|
||||
function select(obj) {
|
||||
// Proxy is always selected
|
||||
if (obj === selection[0]) {
|
||||
return false;
|
||||
}
|
||||
// Clear any existing selection
|
||||
this.deselect();
|
||||
|
||||
// Clear any existing selection
|
||||
deselect();
|
||||
// Note the current selection state
|
||||
this.selectedObj = obj;
|
||||
this.selecting = true;
|
||||
|
||||
// Note the current selection state
|
||||
selected = obj;
|
||||
selecting = true;
|
||||
// Add the selection
|
||||
this.selection.push(obj);
|
||||
};
|
||||
|
||||
// Add the selection
|
||||
selection.push(obj);
|
||||
/**
|
||||
* Clear the current selection.
|
||||
* @returns {boolean} true if selection changed
|
||||
*/
|
||||
EditToolbarSelection.prototype.deselect = function () {
|
||||
// Nothing to do if we don't have a selected object
|
||||
if (this.selecting) {
|
||||
// Clear state tracking
|
||||
this.selecting = false;
|
||||
this.selectedObj = undefined;
|
||||
|
||||
// Remove the selection
|
||||
this.selection.pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the currently-selected object.
|
||||
* @returns the currently selected object
|
||||
*/
|
||||
EditToolbarSelection.prototype.get = function () {
|
||||
return this.selectedObj;
|
||||
};
|
||||
|
||||
// Check if an object is selected
|
||||
function isSelected(obj) {
|
||||
return (obj === selected) || (obj === selection[0]);
|
||||
/**
|
||||
* Get/set the view proxy (for toolbar actions taken upon
|
||||
* the view itself.)
|
||||
* @param [proxy] the view proxy (if setting)
|
||||
* @returns the current view proxy
|
||||
*/
|
||||
EditToolbarSelection.prototype.proxy = function (p) {
|
||||
if (arguments.length > 0) {
|
||||
this.selection[0] = p;
|
||||
}
|
||||
return this.selection[0];
|
||||
};
|
||||
|
||||
// Getter for current selection
|
||||
function get() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
// Getter/setter for view proxy
|
||||
function proxy(p) {
|
||||
if (arguments.length > 0) {
|
||||
selection[0] = p;
|
||||
}
|
||||
return selection[0];
|
||||
}
|
||||
|
||||
// Getter for the full array of selected objects (incl. view proxy)
|
||||
function all() {
|
||||
return selection;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Check if an object is currently selected.
|
||||
* @returns true if selected, otherwise false
|
||||
*/
|
||||
selected: isSelected,
|
||||
/**
|
||||
* Select an object.
|
||||
* @param obj the object to select
|
||||
* @returns {boolean} true if selection changed
|
||||
*/
|
||||
select: select,
|
||||
/**
|
||||
* Clear the current selection.
|
||||
* @returns {boolean} true if selection changed
|
||||
*/
|
||||
deselect: deselect,
|
||||
/**
|
||||
* Get the currently-selected object.
|
||||
* @returns the currently selected object
|
||||
*/
|
||||
get: get,
|
||||
/**
|
||||
* Get/set the view proxy (for toolbar actions taken upon
|
||||
* the view itself.)
|
||||
* @param [proxy] the view proxy (if setting)
|
||||
* @returns the current view proxy
|
||||
*/
|
||||
proxy: proxy,
|
||||
/**
|
||||
* Get an array containing all selections, including the
|
||||
* selection proxy. It is generally not advisable to
|
||||
* mutate this array directly.
|
||||
* @returns {Array} all selections
|
||||
*/
|
||||
all: all
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Get an array containing all selections, including the
|
||||
* selection proxy. It is generally not advisable to
|
||||
* mutate this array directly.
|
||||
* @returns {Array} all selections
|
||||
*/
|
||||
EditToolbarSelection.prototype.all = function () {
|
||||
return this.selection;
|
||||
};
|
||||
|
||||
return EditToolbarSelection;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -112,7 +112,9 @@ define(
|
||||
});
|
||||
|
||||
it("saves objects that have been marked dirty", function () {
|
||||
var objects = ['a', 'b', 'c'].map(TestObject).map(cache.getEditableObject);
|
||||
var objects = ['a', 'b', 'c'].map(TestObject).map(function (domainObject) {
|
||||
return cache.getEditableObject(domainObject);
|
||||
});
|
||||
|
||||
cache.markDirty(objects[0]);
|
||||
cache.markDirty(objects[2]);
|
||||
@@ -123,7 +125,9 @@ define(
|
||||
});
|
||||
|
||||
it("does not save objects that have been marked clean", function () {
|
||||
var objects = ['a', 'b', 'c'].map(TestObject).map(cache.getEditableObject);
|
||||
var objects = ['a', 'b', 'c'].map(TestObject).map(function (domainObject) {
|
||||
return cache.getEditableObject(domainObject);
|
||||
});
|
||||
|
||||
cache.markDirty(objects[0]);
|
||||
cache.markDirty(objects[2]);
|
||||
|
||||
@@ -196,7 +196,7 @@
|
||||
{
|
||||
"key": "label",
|
||||
"templateUrl": "templates/label.html",
|
||||
"uses": [ "type" ],
|
||||
"uses": [ "type", "location" ],
|
||||
"gestures": [ "drag", "menu", "info" ]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/* line 5, ../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
/* line 5, ../../../../../../../../.gem/ruby/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
html, body, div, span, applet, object, iframe,
|
||||
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
||||
a, abbr, acronym, address, big, cite, code,
|
||||
@@ -114,38 +114,38 @@ time, mark, audio, video {
|
||||
font-size: 100%;
|
||||
vertical-align: baseline; }
|
||||
|
||||
/* line 22, ../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
/* line 22, ../../../../../../../../.gem/ruby/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
html {
|
||||
line-height: 1; }
|
||||
|
||||
/* line 24, ../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
/* line 24, ../../../../../../../../.gem/ruby/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
ol, ul {
|
||||
list-style: none; }
|
||||
|
||||
/* line 26, ../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
/* line 26, ../../../../../../../../.gem/ruby/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0; }
|
||||
|
||||
/* line 28, ../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
/* line 28, ../../../../../../../../.gem/ruby/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
caption, th, td {
|
||||
text-align: left;
|
||||
font-weight: normal;
|
||||
vertical-align: middle; }
|
||||
|
||||
/* line 30, ../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
/* line 30, ../../../../../../../../.gem/ruby/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
q, blockquote {
|
||||
quotes: none; }
|
||||
/* line 103, ../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
/* line 103, ../../../../../../../../.gem/ruby/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
q:before, q:after, blockquote:before, blockquote:after {
|
||||
content: "";
|
||||
content: none; }
|
||||
|
||||
/* line 32, ../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
/* line 32, ../../../../../../../../.gem/ruby/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
a img {
|
||||
border: none; }
|
||||
|
||||
/* line 116, ../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
/* line 116, ../../../../../../../../.gem/ruby/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
|
||||
article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, nav, section, summary {
|
||||
display: block; }
|
||||
|
||||
@@ -1240,29 +1240,32 @@ table {
|
||||
table .tr .th:first-child {
|
||||
border-left: none; }
|
||||
/* line 85, ../sass/lists/_tabular.scss */
|
||||
.tabular tr th.sort .icon-sorting:before, .tabular tr .th.sort .icon-sorting:before, .tabular .tr th.sort .icon-sorting:before, .tabular .tr .th.sort .icon-sorting:before,
|
||||
table tr th.sort .icon-sorting:before,
|
||||
table tr .th.sort .icon-sorting:before,
|
||||
table .tr th.sort .icon-sorting:before,
|
||||
table .tr .th.sort .icon-sorting:before {
|
||||
display: inline-block;
|
||||
.tabular tr th.sort.sort:after, .tabular tr .th.sort.sort:after, .tabular .tr th.sort.sort:after, .tabular .tr .th.sort.sort:after,
|
||||
table tr th.sort.sort:after,
|
||||
table tr .th.sort.sort:after,
|
||||
table .tr th.sort.sort:after,
|
||||
table .tr .th.sort.sort:after {
|
||||
color: #49dedb;
|
||||
font-family: symbolsfont;
|
||||
margin-left: 5px; }
|
||||
/* line 90, ../sass/lists/_tabular.scss */
|
||||
.tabular tr th.sort.asc .icon-sorting:before, .tabular tr .th.sort.asc .icon-sorting:before, .tabular .tr th.sort.asc .icon-sorting:before, .tabular .tr .th.sort.asc .icon-sorting:before,
|
||||
table tr th.sort.asc .icon-sorting:before,
|
||||
table tr .th.sort.asc .icon-sorting:before,
|
||||
table .tr th.sort.asc .icon-sorting:before,
|
||||
table .tr .th.sort.asc .icon-sorting:before {
|
||||
content: '0'; }
|
||||
font-size: 8px;
|
||||
content: "\ed";
|
||||
display: inline-block;
|
||||
margin-left: 3px; }
|
||||
/* line 93, ../sass/lists/_tabular.scss */
|
||||
.tabular tr th.sort.desc .icon-sorting:before, .tabular tr .th.sort.desc .icon-sorting:before, .tabular .tr th.sort.desc .icon-sorting:before, .tabular .tr .th.sort.desc .icon-sorting:before,
|
||||
table tr th.sort.desc .icon-sorting:before,
|
||||
table tr .th.sort.desc .icon-sorting:before,
|
||||
table .tr th.sort.desc .icon-sorting:before,
|
||||
table .tr .th.sort.desc .icon-sorting:before {
|
||||
content: '1'; }
|
||||
/* line 98, ../sass/lists/_tabular.scss */
|
||||
.tabular tr th.sort.sort.desc:after, .tabular tr .th.sort.sort.desc:after, .tabular .tr th.sort.sort.desc:after, .tabular .tr .th.sort.sort.desc:after,
|
||||
table tr th.sort.sort.desc:after,
|
||||
table tr .th.sort.sort.desc:after,
|
||||
table .tr th.sort.sort.desc:after,
|
||||
table .tr .th.sort.sort.desc:after {
|
||||
content: "\ec"; }
|
||||
/* line 97, ../sass/lists/_tabular.scss */
|
||||
.tabular tr th.sortable, .tabular tr .th.sortable, .tabular .tr th.sortable, .tabular .tr .th.sortable,
|
||||
table tr th.sortable,
|
||||
table tr .th.sortable,
|
||||
table .tr th.sortable,
|
||||
table .tr .th.sortable {
|
||||
cursor: pointer; }
|
||||
/* line 101, ../sass/lists/_tabular.scss */
|
||||
.tabular tr td, .tabular tr .td, .tabular .tr td, .tabular .tr .td,
|
||||
table tr td,
|
||||
table tr .td,
|
||||
@@ -1274,21 +1277,21 @@ table {
|
||||
padding: 3px 5px;
|
||||
word-wrap: break-word;
|
||||
vertical-align: top; }
|
||||
/* line 105, ../sass/lists/_tabular.scss */
|
||||
/* line 108, ../sass/lists/_tabular.scss */
|
||||
.tabular tr td.numeric, .tabular tr .td.numeric, .tabular .tr td.numeric, .tabular .tr .td.numeric,
|
||||
table tr td.numeric,
|
||||
table tr .td.numeric,
|
||||
table .tr td.numeric,
|
||||
table .tr .td.numeric {
|
||||
text-align: right; }
|
||||
/* line 108, ../sass/lists/_tabular.scss */
|
||||
/* line 111, ../sass/lists/_tabular.scss */
|
||||
.tabular tr td.s-cell-type-value, .tabular tr .td.s-cell-type-value, .tabular .tr td.s-cell-type-value, .tabular .tr .td.s-cell-type-value,
|
||||
table tr td.s-cell-type-value,
|
||||
table tr .td.s-cell-type-value,
|
||||
table .tr td.s-cell-type-value,
|
||||
table .tr .td.s-cell-type-value {
|
||||
text-align: right; }
|
||||
/* line 110, ../sass/lists/_tabular.scss */
|
||||
/* line 113, ../sass/lists/_tabular.scss */
|
||||
.tabular tr td.s-cell-type-value .l-cell-contents, .tabular tr .td.s-cell-type-value .l-cell-contents, .tabular .tr td.s-cell-type-value .l-cell-contents, .tabular .tr .td.s-cell-type-value .l-cell-contents,
|
||||
table tr td.s-cell-type-value .l-cell-contents,
|
||||
table tr .td.s-cell-type-value .l-cell-contents,
|
||||
@@ -1299,23 +1302,23 @@ table {
|
||||
border-radius: 2px;
|
||||
padding-left: 5px;
|
||||
padding-right: 5px; }
|
||||
/* line 126, ../sass/lists/_tabular.scss */
|
||||
/* line 129, ../sass/lists/_tabular.scss */
|
||||
.tabular.filterable tbody, .tabular.filterable .tbody,
|
||||
table.filterable tbody,
|
||||
table.filterable .tbody {
|
||||
top: 44px; }
|
||||
/* line 129, ../sass/lists/_tabular.scss */
|
||||
/* line 132, ../sass/lists/_tabular.scss */
|
||||
.tabular.filterable input[type="text"],
|
||||
table.filterable input[type="text"] {
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
width: 100%; }
|
||||
/* line 135, ../sass/lists/_tabular.scss */
|
||||
/* line 138, ../sass/lists/_tabular.scss */
|
||||
.tabular.fixed-header,
|
||||
table.fixed-header {
|
||||
height: 100%; }
|
||||
/* line 137, ../sass/lists/_tabular.scss */
|
||||
/* line 140, ../sass/lists/_tabular.scss */
|
||||
.tabular.fixed-header thead, .tabular.fixed-header .thead,
|
||||
.tabular.fixed-header tbody tr, .tabular.fixed-header .tbody .tr,
|
||||
table.fixed-header thead,
|
||||
@@ -1324,12 +1327,12 @@ table {
|
||||
table.fixed-header .tbody .tr {
|
||||
display: table;
|
||||
table-layout: fixed; }
|
||||
/* line 142, ../sass/lists/_tabular.scss */
|
||||
/* line 145, ../sass/lists/_tabular.scss */
|
||||
.tabular.fixed-header thead, .tabular.fixed-header .thead,
|
||||
table.fixed-header thead,
|
||||
table.fixed-header .thead {
|
||||
width: calc(100% - 10px); }
|
||||
/* line 144, ../sass/lists/_tabular.scss */
|
||||
/* line 147, ../sass/lists/_tabular.scss */
|
||||
.tabular.fixed-header thead:before, .tabular.fixed-header .thead:before,
|
||||
table.fixed-header thead:before,
|
||||
table.fixed-header .thead:before {
|
||||
@@ -1340,7 +1343,7 @@ table {
|
||||
width: 100%;
|
||||
height: 22px;
|
||||
background: rgba(255, 255, 255, 0.15); }
|
||||
/* line 154, ../sass/lists/_tabular.scss */
|
||||
/* line 157, ../sass/lists/_tabular.scss */
|
||||
.tabular.fixed-header tbody, .tabular.fixed-header .tbody,
|
||||
table.fixed-header tbody,
|
||||
table.fixed-header .tbody {
|
||||
@@ -1355,7 +1358,7 @@ table {
|
||||
top: 22px;
|
||||
display: block;
|
||||
overflow-y: scroll; }
|
||||
/* line 162, ../sass/lists/_tabular.scss */
|
||||
/* line 165, ../sass/lists/_tabular.scss */
|
||||
.tabular.t-event-messages td, .tabular.t-event-messages .td,
|
||||
table.t-event-messages td,
|
||||
table.t-event-messages .td {
|
||||
@@ -4454,26 +4457,26 @@ input[type="text"] {
|
||||
.l-infobubble-wrapper .l-infobubble table tr td {
|
||||
padding: 2px 0;
|
||||
vertical-align: top; }
|
||||
/* line 57, ../sass/helpers/_bubbles.scss */
|
||||
/* line 53, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper .l-infobubble table tr td.label {
|
||||
padding-right: 10px;
|
||||
white-space: nowrap; }
|
||||
/* line 61, ../sass/helpers/_bubbles.scss */
|
||||
/* line 57, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper .l-infobubble table tr td.value {
|
||||
white-space: nowrap; }
|
||||
/* line 65, ../sass/helpers/_bubbles.scss */
|
||||
word-break: break-all; }
|
||||
/* line 61, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper .l-infobubble table tr td.align-wrap {
|
||||
white-space: normal; }
|
||||
/* line 71, ../sass/helpers/_bubbles.scss */
|
||||
/* line 67, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper .l-infobubble .title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
margin-bottom: 5px; }
|
||||
/* line 78, ../sass/helpers/_bubbles.scss */
|
||||
/* line 74, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper.arw-left {
|
||||
margin-left: 20px; }
|
||||
/* line 80, ../sass/helpers/_bubbles.scss */
|
||||
/* line 76, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper.arw-left .l-infobubble::before {
|
||||
right: 100%;
|
||||
width: 0;
|
||||
@@ -4481,10 +4484,10 @@ input[type="text"] {
|
||||
border-top: 6.66667px solid transparent;
|
||||
border-bottom: 6.66667px solid transparent;
|
||||
border-right: 10px solid #ddd; }
|
||||
/* line 86, ../sass/helpers/_bubbles.scss */
|
||||
/* line 82, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper.arw-right {
|
||||
margin-right: 20px; }
|
||||
/* line 88, ../sass/helpers/_bubbles.scss */
|
||||
/* line 84, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper.arw-right .l-infobubble::before {
|
||||
left: 100%;
|
||||
width: 0;
|
||||
@@ -4492,16 +4495,16 @@ input[type="text"] {
|
||||
border-top: 6.66667px solid transparent;
|
||||
border-bottom: 6.66667px solid transparent;
|
||||
border-left: 10px solid #ddd; }
|
||||
/* line 95, ../sass/helpers/_bubbles.scss */
|
||||
/* line 91, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper.arw-top .l-infobubble::before {
|
||||
top: 20px; }
|
||||
/* line 101, ../sass/helpers/_bubbles.scss */
|
||||
/* line 97, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper.arw-btm .l-infobubble::before {
|
||||
bottom: 20px; }
|
||||
/* line 106, ../sass/helpers/_bubbles.scss */
|
||||
/* line 102, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper.arw-down {
|
||||
margin-bottom: 10px; }
|
||||
/* line 108, ../sass/helpers/_bubbles.scss */
|
||||
/* line 104, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper.arw-down .l-infobubble::before {
|
||||
left: 50%;
|
||||
top: 100%;
|
||||
@@ -4509,21 +4512,21 @@ input[type="text"] {
|
||||
border-left: 5px solid transparent;
|
||||
border-right: 5px solid transparent;
|
||||
border-top: 7.5px solid #ddd; }
|
||||
/* line 117, ../sass/helpers/_bubbles.scss */
|
||||
/* line 113, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper .arw {
|
||||
z-index: 2; }
|
||||
/* line 120, ../sass/helpers/_bubbles.scss */
|
||||
/* line 116, ../sass/helpers/_bubbles.scss */
|
||||
.l-infobubble-wrapper.arw-up .arw.arw-down, .l-infobubble-wrapper.arw-down .arw.arw-up {
|
||||
display: none; }
|
||||
|
||||
/* line 127, ../sass/helpers/_bubbles.scss */
|
||||
/* line 125, ../sass/helpers/_bubbles.scss */
|
||||
.l-thumbsbubble-wrapper .arw-up {
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 6.66667px solid transparent;
|
||||
border-right: 6.66667px solid transparent;
|
||||
border-bottom: 10px solid #4d4d4d; }
|
||||
/* line 130, ../sass/helpers/_bubbles.scss */
|
||||
/* line 128, ../sass/helpers/_bubbles.scss */
|
||||
.l-thumbsbubble-wrapper .arw-down {
|
||||
width: 0;
|
||||
height: 0;
|
||||
@@ -4531,7 +4534,7 @@ input[type="text"] {
|
||||
border-right: 6.66667px solid transparent;
|
||||
border-top: 10px solid #4d4d4d; }
|
||||
|
||||
/* line 134, ../sass/helpers/_bubbles.scss */
|
||||
/* line 133, ../sass/helpers/_bubbles.scss */
|
||||
.s-infobubble {
|
||||
-moz-border-radius: 2px;
|
||||
-webkit-border-radius: 2px;
|
||||
@@ -4542,22 +4545,29 @@ input[type="text"] {
|
||||
background: #ddd;
|
||||
color: #666;
|
||||
font-size: 0.8rem; }
|
||||
/* line 141, ../sass/helpers/_bubbles.scss */
|
||||
/* line 140, ../sass/helpers/_bubbles.scss */
|
||||
.s-infobubble .title {
|
||||
color: #333333;
|
||||
font-weight: bold; }
|
||||
/* line 146, ../sass/helpers/_bubbles.scss */
|
||||
.s-infobubble tr td {
|
||||
border-top: 1px solid #c4c4c4;
|
||||
.s-infobubble table tr td {
|
||||
border: none;
|
||||
border-top: 1px solid #c4c4c4 !important;
|
||||
font-size: 0.9em; }
|
||||
/* line 150, ../sass/helpers/_bubbles.scss */
|
||||
.s-infobubble tr:first-child td {
|
||||
/* line 152, ../sass/helpers/_bubbles.scss */
|
||||
.s-infobubble table tr:first-child td {
|
||||
border-top: none !important; }
|
||||
/* line 157, ../sass/helpers/_bubbles.scss */
|
||||
.s-infobubble:first-child td {
|
||||
border-top: none; }
|
||||
/* line 154, ../sass/helpers/_bubbles.scss */
|
||||
/* line 161, ../sass/helpers/_bubbles.scss */
|
||||
.s-infobubble .label {
|
||||
color: gray; }
|
||||
/* line 165, ../sass/helpers/_bubbles.scss */
|
||||
.s-infobubble .value {
|
||||
color: #333333; }
|
||||
|
||||
/* line 159, ../sass/helpers/_bubbles.scss */
|
||||
/* line 171, ../sass/helpers/_bubbles.scss */
|
||||
.s-thumbsbubble {
|
||||
background: #4d4d4d;
|
||||
color: #b3b3b3; }
|
||||
|
||||
@@ -124,8 +124,8 @@ ul.tree {
|
||||
transition: background-color 0.25s;
|
||||
display: block;
|
||||
font-size: 0.8em;
|
||||
height: 1.4rem;
|
||||
line-height: 1.4rem;
|
||||
height: 1.5rem;
|
||||
line-height: 1.5rem;
|
||||
margin-bottom: 3px;
|
||||
position: relative; }
|
||||
/* line 39, ../sass/tree/_tree.scss */
|
||||
|
||||
@@ -147,7 +147,7 @@ $controlDisabledOpacity: 0.3;
|
||||
$formLabelW: 20%;
|
||||
$formInputH: 22px;
|
||||
$formRowCtrlsH: 14px;
|
||||
$menuLineH: 1.4rem;
|
||||
$menuLineH: 1.5rem;
|
||||
$scrollbarTrackSize: 10px;
|
||||
$scrollbarTrackColorBg: rgba(#000, 0.4);
|
||||
$btnStdH: 25px;
|
||||
|
||||
@@ -48,19 +48,15 @@
|
||||
width: 100%;
|
||||
tr {
|
||||
td {
|
||||
//max-width: 150px;
|
||||
padding: 2px 0;
|
||||
vertical-align: top;
|
||||
//white-space: nowrap;
|
||||
//overflow: hidden;
|
||||
//text-overflow: ellipsis;
|
||||
&.label {
|
||||
padding-right: $interiorMargin * 2;
|
||||
white-space: nowrap;
|
||||
}
|
||||
&.value {
|
||||
white-space: nowrap;
|
||||
//width: 90%;
|
||||
//word-wrap: break-word; // Doesn't work in <td>?
|
||||
word-break: break-all;
|
||||
}
|
||||
&.align-wrap {
|
||||
white-space: normal;
|
||||
@@ -118,7 +114,9 @@
|
||||
z-index: 2;
|
||||
}
|
||||
&.arw-up .arw.arw-down,
|
||||
&.arw-down .arw.arw-up { display: none; }
|
||||
&.arw-down .arw.arw-up {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
//************************************************* LOOK AND FEEL
|
||||
@@ -131,6 +129,7 @@
|
||||
@include triangle('down', $bubbleArwSize, 1.5, $colorThumbsBubbleBg);
|
||||
}
|
||||
}
|
||||
|
||||
.s-infobubble {
|
||||
$emFg: darken($colorInfoBubbleFg, 20%);
|
||||
@include border-radius($basicCr);
|
||||
@@ -142,18 +141,31 @@
|
||||
color: $emFg;
|
||||
font-weight: bold;
|
||||
}
|
||||
tr {
|
||||
td {
|
||||
border-top: 1px solid darken($colorInfoBubbleBg, 10%);
|
||||
font-size: 0.9em;
|
||||
}
|
||||
&:first-child td {
|
||||
border-top: none;
|
||||
table {
|
||||
tr {
|
||||
td {
|
||||
border: none;
|
||||
border-top: 1px solid darken($colorInfoBubbleBg, 10%) !important;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
&:first-child td {
|
||||
border-top: none !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
&:first-child td {
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: lighten($emFg, 30%);
|
||||
}
|
||||
|
||||
.value {
|
||||
color: $emFg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.s-thumbsbubble {
|
||||
|
||||
@@ -82,18 +82,21 @@ table {
|
||||
border-left: none;
|
||||
}
|
||||
&.sort {
|
||||
.icon-sorting:before {
|
||||
display: inline-block;
|
||||
&.sort:after {
|
||||
color: $colorIconLink;
|
||||
font-family: symbolsfont;
|
||||
margin-left: 5px;
|
||||
font-size: 8px;
|
||||
content: "\ed";
|
||||
display: inline-block;
|
||||
margin-left: $interiorMarginSm;
|
||||
}
|
||||
&.asc .icon-sorting:before {
|
||||
content: '0';
|
||||
}
|
||||
&.desc .icon-sorting:before {
|
||||
content: '1';
|
||||
&.sort.desc:after {
|
||||
content: "\ec";
|
||||
}
|
||||
}
|
||||
&.sortable {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
td, .td {
|
||||
border-bottom: 1px solid $tabularColorBorder;
|
||||
|
||||
@@ -22,7 +22,13 @@
|
||||
<span class="label s-label">
|
||||
<span class='ui-symbol icon type-icon'>
|
||||
{{type.getGlyph()}}
|
||||
<span class='ui-symbol icon alert hidden'>!</span>
|
||||
<span
|
||||
class='ui-symbol icon l-icon-link'
|
||||
ng-show="location.isLink()"
|
||||
></span>
|
||||
<span class='ui-symbol icon l-icon-alert'></span>
|
||||
</span>
|
||||
<span class='title-label'>
|
||||
{{model.name}}
|
||||
</span>
|
||||
<span class='title-label'>{{model.name}}</span>
|
||||
</span>
|
||||
|
||||
@@ -22,29 +22,29 @@
|
||||
<span ng-controller="ToggleController as toggle">
|
||||
<span ng-controller="TreeNodeController as treeNode">
|
||||
<span
|
||||
class="tree-item menus-to-left"
|
||||
ng-class="{selected: treeNode.isSelected()}"
|
||||
>
|
||||
class="tree-item menus-to-left"
|
||||
ng-class="{selected: treeNode.isSelected()}"
|
||||
>
|
||||
<span
|
||||
class='ui-symbol view-control'
|
||||
ng-click="toggle.toggle(); treeNode.trackExpansion()"
|
||||
ng-if="model.composition !== undefined"
|
||||
>
|
||||
class='ui-symbol view-control'
|
||||
ng-click="toggle.toggle(); treeNode.trackExpansion()"
|
||||
ng-if="model.composition !== undefined"
|
||||
>
|
||||
{{toggle.isActive() ? "v" : ">"}}
|
||||
</span>
|
||||
<mct-representation
|
||||
key="'label'"
|
||||
mct-object="domainObject"
|
||||
ng-model="ngModel"
|
||||
ng-click="ngModel.selectedObject = domainObject"
|
||||
>
|
||||
key="'label'"
|
||||
mct-object="domainObject"
|
||||
ng-model="ngModel"
|
||||
ng-click="ngModel.selectedObject = domainObject"
|
||||
>
|
||||
</mct-representation>
|
||||
</span>
|
||||
<span
|
||||
class="tree-item-subtree"
|
||||
ng-show="toggle.isActive()"
|
||||
ng-if="model.composition !== undefined"
|
||||
>
|
||||
class="tree-item-subtree"
|
||||
ng-show="toggle.isActive()"
|
||||
ng-if="model.composition !== undefined"
|
||||
>
|
||||
|
||||
<mct-representation key="'subtree'"
|
||||
ng-model="ngModel"
|
||||
|
||||
@@ -21,6 +21,11 @@
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
/**
|
||||
* This bundle provides various general-purpose UI elements, including
|
||||
* platform styling.
|
||||
* @namespace platform/commonUI/general
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
@@ -29,6 +34,7 @@ define(
|
||||
/**
|
||||
* The StyleSheetLoader adds links to style sheets exposed from
|
||||
* various bundles as extensions of category `stylesheets`.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param {object[]} stylesheets stylesheet extension definitions
|
||||
* @param $document Angular's jqLite-wrapped document element
|
||||
@@ -62,4 +68,4 @@ define(
|
||||
|
||||
return StyleSheetLoader;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -42,6 +42,7 @@ define(
|
||||
* * `ungrouped`: All actions which did not have a defined
|
||||
* group.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function ActionGroupController($scope) {
|
||||
@@ -102,4 +103,4 @@ define(
|
||||
|
||||
return ActionGroupController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -29,6 +29,7 @@ define(
|
||||
/**
|
||||
* Controller for the bottombar template. Exposes
|
||||
* available indicators (of extension category "indicators")
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function BottomBarController(indicators) {
|
||||
@@ -42,20 +43,19 @@ define(
|
||||
};
|
||||
}
|
||||
|
||||
indicators = indicators.map(present);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get all indicators to display.
|
||||
* @returns {Indicator[]} all indicators
|
||||
* to display in the bottom bar.
|
||||
*/
|
||||
getIndicators: function () {
|
||||
return indicators;
|
||||
}
|
||||
};
|
||||
this.indicators = indicators.map(present);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all indicators to display.
|
||||
* @returns {Indicator[]} all indicators
|
||||
* to display in the bottom bar.
|
||||
* @memberof platform/commonUI/general.BottomBarController#
|
||||
*/
|
||||
BottomBarController.prototype.getIndicators = function () {
|
||||
return this.indicators;
|
||||
};
|
||||
|
||||
return BottomBarController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -31,71 +31,69 @@ define(
|
||||
* menus) where clicking elsewhere in the document while the toggle
|
||||
* is in an active state is intended to dismiss the toggle.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param $scope the scope in which this controller is active
|
||||
* @param $document the document element, injected by Angular
|
||||
*/
|
||||
function ClickAwayController($scope, $document) {
|
||||
var state = false,
|
||||
clickaway;
|
||||
var self = this;
|
||||
|
||||
// Track state, but also attach and detach a listener for
|
||||
// mouseup events on the document.
|
||||
function deactivate() {
|
||||
state = false;
|
||||
$document.off("mouseup", clickaway);
|
||||
}
|
||||
|
||||
function activate() {
|
||||
state = true;
|
||||
$document.on("mouseup", clickaway);
|
||||
}
|
||||
|
||||
function changeState() {
|
||||
if (state) {
|
||||
deactivate();
|
||||
} else {
|
||||
activate();
|
||||
}
|
||||
}
|
||||
this.state = false;
|
||||
this.$scope = $scope;
|
||||
this.$document = $document;
|
||||
|
||||
// Callback used by the document listener. Deactivates;
|
||||
// note also $scope.$apply is invoked to indicate that
|
||||
// the state of this controller has changed.
|
||||
clickaway = function () {
|
||||
deactivate();
|
||||
this.clickaway = function () {
|
||||
self.deactivate();
|
||||
$scope.$apply();
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the current state of the toggle.
|
||||
* @return {boolean} true if active
|
||||
*/
|
||||
isActive: function () {
|
||||
return state;
|
||||
},
|
||||
/**
|
||||
* Set a new state for the toggle.
|
||||
* @return {boolean} true to activate
|
||||
*/
|
||||
setState: function (newState) {
|
||||
if (state !== newState) {
|
||||
changeState();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Toggle the current state; activate if it is inactive,
|
||||
* deactivate if it is active.
|
||||
*/
|
||||
toggle: function () {
|
||||
changeState();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// Track state, but also attach and detach a listener for
|
||||
// mouseup events on the document.
|
||||
ClickAwayController.prototype.deactivate = function () {
|
||||
this.state = false;
|
||||
this.$document.off("mouseup", this.clickaway);
|
||||
};
|
||||
ClickAwayController.prototype.activate = function () {
|
||||
this.state = true;
|
||||
this.$document.on("mouseup", this.clickaway);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the current state of the toggle.
|
||||
* @return {boolean} true if active
|
||||
*/
|
||||
ClickAwayController.prototype.isActive =function () {
|
||||
return this.state;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set a new state for the toggle.
|
||||
* @return {boolean} true to activate
|
||||
*/
|
||||
ClickAwayController.prototype.setState = function (newState) {
|
||||
if (this.state !== newState) {
|
||||
this.toggle();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle the current state; activate if it is inactive,
|
||||
* deactivate if it is active.
|
||||
*/
|
||||
ClickAwayController.prototype.toggle = function () {
|
||||
if (this.state) {
|
||||
this.deactivate();
|
||||
} else {
|
||||
this.activate();
|
||||
}
|
||||
};
|
||||
|
||||
return ClickAwayController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -33,6 +33,7 @@ define(
|
||||
* Controller for the context menu. Maintains an up-to-date
|
||||
* list of applicable actions (those from category "contextual")
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function ContextMenuController($scope) {
|
||||
@@ -49,4 +50,4 @@ define(
|
||||
|
||||
return ContextMenuController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -54,6 +54,7 @@ define(
|
||||
* parameter it received.) Getter-setter functions are never the
|
||||
* target of a scope assignment and so avoid this problem.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param {Scope} $scope the controller's scope
|
||||
*/
|
||||
@@ -87,4 +88,4 @@ define(
|
||||
return GetterSetterController;
|
||||
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -30,6 +30,7 @@ define(
|
||||
|
||||
/**
|
||||
* Controller for the domain object selector control.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param {ObjectService} objectService service from which to
|
||||
* read domain objects
|
||||
@@ -38,28 +39,17 @@ define(
|
||||
function SelectorController(objectService, $scope) {
|
||||
var treeModel = {},
|
||||
listModel = {},
|
||||
selectedObjects = [],
|
||||
rootObject,
|
||||
previousSelected;
|
||||
previousSelected,
|
||||
self = this;
|
||||
|
||||
// For watch; look at the user's selection in the tree
|
||||
function getTreeSelection() {
|
||||
return treeModel.selectedObject;
|
||||
}
|
||||
|
||||
// Get the value of the field being edited
|
||||
function getField() {
|
||||
return $scope.ngModel[$scope.field] || [];
|
||||
}
|
||||
|
||||
// Get the value of the field being edited
|
||||
function setField(value) {
|
||||
$scope.ngModel[$scope.field] = value;
|
||||
}
|
||||
|
||||
// Store root object for subsequent exposure to template
|
||||
function storeRoot(objects) {
|
||||
rootObject = objects[ROOT_ID];
|
||||
self.rootObject = objects[ROOT_ID];
|
||||
}
|
||||
|
||||
// Check that a selection is of the valid type
|
||||
@@ -82,7 +72,8 @@ define(
|
||||
function updateSelectedObjects(objects) {
|
||||
// Look up from the
|
||||
function getObject(id) { return objects[id]; }
|
||||
selectedObjects = ids.filter(getObject).map(getObject);
|
||||
self.selectedObjects =
|
||||
ids.filter(getObject).map(getObject);
|
||||
}
|
||||
|
||||
// Look up objects by id, then populate right-hand list
|
||||
@@ -93,64 +84,85 @@ define(
|
||||
$scope.$watch(getTreeSelection, validateTreeSelection);
|
||||
|
||||
// Make sure right-hand list matches underlying model
|
||||
$scope.$watchCollection(getField, updateList);
|
||||
$scope.$watchCollection(function () {
|
||||
return self.getField();
|
||||
}, updateList);
|
||||
|
||||
// Look up root object, then store it
|
||||
objectService.getObjects([ROOT_ID]).then(storeRoot);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the root object to show in the left-hand tree.
|
||||
* @returns {DomainObject} the root object
|
||||
*/
|
||||
root: function () {
|
||||
return rootObject;
|
||||
},
|
||||
/**
|
||||
* Add a domain object to the list of selected objects.
|
||||
* @param {DomainObject} the domain object to select
|
||||
*/
|
||||
select: function (domainObject) {
|
||||
var id = domainObject && domainObject.getId(),
|
||||
list = getField() || [];
|
||||
// Only select if we have a valid id,
|
||||
// and it isn't already selected
|
||||
if (id && list.indexOf(id) === -1) {
|
||||
setField(list.concat([id]));
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Remove a domain object from the list of selected objects.
|
||||
* @param {DomainObject} the domain object to select
|
||||
*/
|
||||
deselect: function (domainObject) {
|
||||
var id = domainObject && domainObject.getId(),
|
||||
list = getField() || [];
|
||||
// Only change if this was a valid id,
|
||||
// for an object which was already selected
|
||||
if (id && list.indexOf(id) !== -1) {
|
||||
// Filter it out of the current field
|
||||
setField(list.filter(function (otherId) {
|
||||
return otherId !== id;
|
||||
}));
|
||||
// Clear the current list selection
|
||||
delete listModel.selectedObject;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Get the currently-selected domain objects.
|
||||
* @returns {DomainObject[]} the current selection
|
||||
*/
|
||||
selected: function () {
|
||||
return selectedObjects;
|
||||
},
|
||||
// Expose tree/list model for use in template directly
|
||||
treeModel: treeModel,
|
||||
listModel: listModel
|
||||
};
|
||||
this.$scope = $scope;
|
||||
this.selectedObjects = [];
|
||||
|
||||
// Expose tree/list model for use in template directly
|
||||
this.treeModel = treeModel;
|
||||
this.listModel = listModel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Set the value of the field being edited
|
||||
SelectorController.prototype.setField = function (value) {
|
||||
this.$scope.ngModel[this.$scope.field] = value;
|
||||
};
|
||||
|
||||
// Get the value of the field being edited
|
||||
SelectorController.prototype.getField = function () {
|
||||
return this.$scope.ngModel[this.$scope.field] || [];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the root object to show in the left-hand tree.
|
||||
* @returns {DomainObject} the root object
|
||||
*/
|
||||
SelectorController.prototype.root = function () {
|
||||
return this.rootObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a domain object to the list of selected objects.
|
||||
* @param {DomainObject} the domain object to select
|
||||
*/
|
||||
SelectorController.prototype.select = function (domainObject) {
|
||||
var id = domainObject && domainObject.getId(),
|
||||
list = this.getField() || [];
|
||||
// Only select if we have a valid id,
|
||||
// and it isn't already selected
|
||||
if (id && list.indexOf(id) === -1) {
|
||||
this.setField(list.concat([id]));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a domain object from the list of selected objects.
|
||||
* @param {DomainObject} the domain object to select
|
||||
*/
|
||||
SelectorController.prototype.deselect = function (domainObject) {
|
||||
var id = domainObject && domainObject.getId(),
|
||||
list = this.getField() || [];
|
||||
// Only change if this was a valid id,
|
||||
// for an object which was already selected
|
||||
if (id && list.indexOf(id) !== -1) {
|
||||
// Filter it out of the current field
|
||||
this.setField(list.filter(function (otherId) {
|
||||
return otherId !== id;
|
||||
}));
|
||||
// Clear the current list selection
|
||||
delete this.listModel.selectedObject;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the currently-selected domain objects.
|
||||
* @returns {DomainObject[]} the current selection
|
||||
*/
|
||||
SelectorController.prototype.selected = function () {
|
||||
return this.selectedObjects;
|
||||
};
|
||||
|
||||
|
||||
return SelectorController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -32,59 +32,58 @@ define(
|
||||
/**
|
||||
* Controller for the splitter in Browse mode. Current implementation
|
||||
* uses many hard-coded constants; this could be generalized.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function SplitPaneController() {
|
||||
var current = 200,
|
||||
start = 200,
|
||||
assigned = false;
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the current position of the splitter, in pixels
|
||||
* from the left edge.
|
||||
* @returns {number} position of the splitter, in pixels
|
||||
*/
|
||||
state: function (defaultState) {
|
||||
// Set the state to the desired default, if we don't have a
|
||||
// "real" current state yet.
|
||||
if (arguments.length > 0 && !assigned) {
|
||||
current = defaultState;
|
||||
assigned = true;
|
||||
}
|
||||
return current;
|
||||
},
|
||||
/**
|
||||
* Begin moving the splitter; this will note the splitter's
|
||||
* current position, which is necessary for correct
|
||||
* interpretation of deltas provided by mct-drag.
|
||||
*/
|
||||
startMove: function () {
|
||||
start = current;
|
||||
},
|
||||
/**
|
||||
* Move the splitter a number of pixels to the right
|
||||
* (negative numbers move the splitter to the left.)
|
||||
* This movement is relative to the position of the
|
||||
* splitter when startMove was last invoked.
|
||||
* @param {number} delta number of pixels to move
|
||||
*/
|
||||
move: function (delta, minimum, maximum) {
|
||||
// Ensure defaults for minimum/maximum
|
||||
maximum = isNaN(maximum) ? DEFAULT_MAXIMUM : maximum;
|
||||
minimum = isNaN(minimum) ? DEFAULT_MINIMUM : minimum;
|
||||
|
||||
// Update current splitter state
|
||||
current = Math.min(
|
||||
maximum,
|
||||
Math.max(minimum, start + delta)
|
||||
);
|
||||
|
||||
//console.log(current + "; minimum: " + minimum + "; max: " + maximum);
|
||||
}
|
||||
};
|
||||
this.current = 200;
|
||||
this.start = 200;
|
||||
this.assigned = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current position of the splitter, in pixels
|
||||
* from the left edge.
|
||||
* @returns {number} position of the splitter, in pixels
|
||||
*/
|
||||
SplitPaneController.prototype.state = function (defaultState) {
|
||||
// Set the state to the desired default, if we don't have a
|
||||
// "real" current state yet.
|
||||
if (arguments.length > 0 && !this.assigned) {
|
||||
this.current = defaultState;
|
||||
this.assigned = true;
|
||||
}
|
||||
return this.current;
|
||||
};
|
||||
|
||||
/**
|
||||
* Begin moving the splitter; this will note the splitter's
|
||||
* current position, which is necessary for correct
|
||||
* interpretation of deltas provided by mct-drag.
|
||||
*/
|
||||
SplitPaneController.prototype.startMove = function () {
|
||||
this.start = this.current;
|
||||
};
|
||||
|
||||
/**
|
||||
* Move the splitter a number of pixels to the right
|
||||
* (negative numbers move the splitter to the left.)
|
||||
* This movement is relative to the position of the
|
||||
* splitter when startMove was last invoked.
|
||||
* @param {number} delta number of pixels to move
|
||||
*/
|
||||
SplitPaneController.prototype.move = function (delta, minimum, maximum) {
|
||||
// Ensure defaults for minimum/maximum
|
||||
maximum = isNaN(maximum) ? DEFAULT_MAXIMUM : maximum;
|
||||
minimum = isNaN(minimum) ? DEFAULT_MINIMUM : minimum;
|
||||
|
||||
// Update current splitter state
|
||||
this.current = Math.min(
|
||||
maximum,
|
||||
Math.max(minimum, this.start + delta)
|
||||
);
|
||||
};
|
||||
|
||||
return SplitPaneController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -30,37 +30,37 @@ define(
|
||||
* A ToggleController is used to activate/deactivate things.
|
||||
* A common usage is for "twistie"
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function ToggleController() {
|
||||
var state = false;
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get the current state of the toggle.
|
||||
* @return {boolean} true if active
|
||||
*/
|
||||
isActive: function () {
|
||||
return state;
|
||||
},
|
||||
/**
|
||||
* Set a new state for the toggle.
|
||||
* @return {boolean} true to activate
|
||||
*/
|
||||
setState: function (newState) {
|
||||
state = newState;
|
||||
},
|
||||
/**
|
||||
* Toggle the current state; activate if it is inactive,
|
||||
* deactivate if it is active.
|
||||
*/
|
||||
toggle: function () {
|
||||
state = !state;
|
||||
}
|
||||
};
|
||||
|
||||
this.state = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current state of the toggle.
|
||||
* @return {boolean} true if active
|
||||
*/
|
||||
ToggleController.prototype.isActive = function () {
|
||||
return this.state;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set a new state for the toggle.
|
||||
* @return {boolean} true to activate
|
||||
*/
|
||||
ToggleController.prototype.setState = function (newState) {
|
||||
this.state = newState;
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle the current state; activate if it is inactive,
|
||||
* deactivate if it is active.
|
||||
*/
|
||||
ToggleController.prototype.toggle = function () {
|
||||
this.state = !this.state;
|
||||
};
|
||||
|
||||
return ToggleController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -48,12 +48,12 @@ define(
|
||||
* node expansion when this tree node's _subtree_ will contain
|
||||
* the navigated object (recursively, this becomes an
|
||||
* expand-to-show-navigated-object behavior.)
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function TreeNodeController($scope, $timeout, $rootScope) {
|
||||
var selectedObject = ($scope.ngModel || {}).selectedObject,
|
||||
isSelected = false,
|
||||
hasBeenExpanded = false;
|
||||
function TreeNodeController($scope, $timeout) {
|
||||
var self = this,
|
||||
selectedObject = ($scope.ngModel || {}).selectedObject;
|
||||
|
||||
// Look up the id for a domain object. A convenience
|
||||
// for mapping; additionally does some undefined-checking.
|
||||
@@ -76,17 +76,6 @@ define(
|
||||
checkPath(nodePath, navPath, index + 1));
|
||||
}
|
||||
|
||||
// Track that a node has been expanded, either by the
|
||||
// user or automatically to show a selection.
|
||||
function trackExpansion() {
|
||||
if (!hasBeenExpanded) {
|
||||
// Run on a timeout; if a lot of expansion needs to
|
||||
// occur (e.g. if the selection is several nodes deep) we
|
||||
// want this to be spread across multiple digest cycles.
|
||||
$timeout(function () { hasBeenExpanded = true; }, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Consider the currently-navigated object and update
|
||||
// parameters which support display.
|
||||
function checkSelection() {
|
||||
@@ -101,7 +90,7 @@ define(
|
||||
|
||||
// Deselect; we will reselect below, iff we are
|
||||
// exactly at the end of the path.
|
||||
isSelected = false;
|
||||
self.isSelectedFlag = false;
|
||||
|
||||
// Expand if necessary (if the navigated object will
|
||||
// be in this node's subtree)
|
||||
@@ -120,12 +109,12 @@ define(
|
||||
// at the end of the path, highlight;
|
||||
// otherwise, expand.
|
||||
if (nodePath.length === navPath.length) {
|
||||
isSelected = true;
|
||||
self.isSelectedFlag = true;
|
||||
} else { // node path is shorter: Expand!
|
||||
if ($scope.toggle) {
|
||||
$scope.toggle.setState(true);
|
||||
}
|
||||
trackExpansion();
|
||||
self.trackExpansion();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -138,49 +127,52 @@ define(
|
||||
selectedObject = object;
|
||||
checkSelection();
|
||||
}
|
||||
|
||||
|
||||
this.isSelectedFlag = false;
|
||||
this.hasBeenExpandedFlag = false;
|
||||
this.$timeout = $timeout;
|
||||
|
||||
// Listen for changes which will effect display parameters
|
||||
$scope.$watch("ngModel.selectedObject", setSelection);
|
||||
$scope.$watch("domainObject", checkSelection);
|
||||
|
||||
return {
|
||||
/**
|
||||
* This method should be called when a node is expanded
|
||||
* to record that this has occurred, to support one-time
|
||||
* lazy loading of the node's subtree.
|
||||
*/
|
||||
trackExpansion: trackExpansion,
|
||||
/**
|
||||
* Check if this not has ever been expanded.
|
||||
* @returns true if it has been expanded
|
||||
*/
|
||||
hasBeenExpanded: function () {
|
||||
return hasBeenExpanded;
|
||||
},
|
||||
/**
|
||||
* Check whether or not the domain object represented by
|
||||
* this tree node should be highlighted.
|
||||
* An object will be highlighted if it matches
|
||||
* ngModel.selectedObject
|
||||
* @returns true if this should be highlighted
|
||||
*/
|
||||
isSelected: function () {
|
||||
return isSelected;
|
||||
|
||||
// Modification for compatibility with search.
|
||||
// If this object is the same as the model's selected object
|
||||
// Same being them having the same ID (this allows different
|
||||
// instances of the same thing to be recognized as the same)
|
||||
//return getId($scope.ngModel.selectedObject) === getId($scope.domainObject);
|
||||
|
||||
// Not using modified version now because it breaks tests.
|
||||
|
||||
// TODO: Check to make sure this change doesn't break
|
||||
// anything/find a better way to do this
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should be called when a node is expanded
|
||||
* to record that this has occurred, to support one-time
|
||||
* lazy loading of the node's subtree.
|
||||
*/
|
||||
TreeNodeController.prototype.trackExpansion = function () {
|
||||
var self = this;
|
||||
if (!self.hasBeenExpanded()) {
|
||||
// Run on a timeout; if a lot of expansion needs to
|
||||
// occur (e.g. if the selection is several nodes deep) we
|
||||
// want this to be spread across multiple digest cycles.
|
||||
self.$timeout(function () {
|
||||
self.hasBeenExpandedFlag = true;
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this not has ever been expanded.
|
||||
* @returns true if it has been expanded
|
||||
*/
|
||||
TreeNodeController.prototype.hasBeenExpanded = function () {
|
||||
return this.hasBeenExpandedFlag;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether or not the domain object represented by
|
||||
* this tree node should be highlighted.
|
||||
* An object will be highlighted if it matches
|
||||
* ngModel.selectedObject
|
||||
* @returns true if this should be highlighted
|
||||
*/
|
||||
TreeNodeController.prototype.isSelected = function () {
|
||||
return this.isSelectedFlag;
|
||||
};
|
||||
|
||||
return TreeNodeController;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -32,6 +32,7 @@ define(
|
||||
/**
|
||||
* Controller for the view switcher; populates and maintains a list
|
||||
* of applicable views for a represented domain object.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function ViewSwitcherController($scope, $timeout) {
|
||||
@@ -71,3 +72,4 @@ define(
|
||||
return ViewSwitcherController;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ define(
|
||||
* plain string attribute, instead of as an Angular
|
||||
* expression.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function MCTContainer(containers) {
|
||||
@@ -96,4 +97,4 @@ define(
|
||||
|
||||
return MCTContainer;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -44,6 +44,7 @@ define(
|
||||
* and vertical pixel offset of the current mouse position
|
||||
* relative to the mouse position where dragging began.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*
|
||||
*/
|
||||
@@ -157,3 +158,4 @@ define(
|
||||
return MCTDrag;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ define(
|
||||
* This is an Angular expression, and it will be re-evaluated after
|
||||
* each interval.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*
|
||||
*/
|
||||
@@ -111,4 +112,4 @@ define(
|
||||
|
||||
return MCTResize;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -37,6 +37,7 @@ define(
|
||||
* This is exposed as two directives in `bundle.json`; the difference
|
||||
* is handled purely by parameterization.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @param $parse Angular's $parse
|
||||
* @param {string} property property to manage within the HTML element
|
||||
@@ -80,4 +81,4 @@ define(
|
||||
return MCTScroll;
|
||||
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -91,6 +91,7 @@ define(
|
||||
* etc. can be set on that element to control the splitter's
|
||||
* allowable positions.
|
||||
*
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function MCTSplitPane($parse, $log) {
|
||||
@@ -213,3 +214,4 @@ define(
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ define(
|
||||
|
||||
/**
|
||||
* Implements `mct-splitter` directive.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function MCTSplitter() {
|
||||
@@ -88,3 +89,4 @@ define(
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -32,62 +32,56 @@ define(
|
||||
/**
|
||||
* The url service handles calls for url paths
|
||||
* using domain objects.
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/general
|
||||
*/
|
||||
function UrlService($location) {
|
||||
// Returns the url for the mode wanted
|
||||
// and the domainObject passed in. A path
|
||||
// is returned. The view is defaulted to
|
||||
// the current location's (current object's)
|
||||
// view set.
|
||||
function urlForLocation(mode, domainObject) {
|
||||
var context = domainObject &&
|
||||
domainObject.getCapability('context'),
|
||||
objectPath = context ? context.getPath() : [],
|
||||
ids = objectPath.map(function (domainObject) {
|
||||
return domainObject.getId();
|
||||
}),
|
||||
// Parses the path together. Starts with the
|
||||
// default index.html file, then the mode passed
|
||||
// into the service, followed by ids in the url
|
||||
// joined by '/', and lastly the view path from
|
||||
// the current location
|
||||
path = mode + "/" + ids.slice(1).join("/");
|
||||
return path;
|
||||
}
|
||||
|
||||
// Uses the Url for the current location
|
||||
// from the urlForLocation function and
|
||||
// includes the view and the index path
|
||||
function urlForNewTab(mode, domainObject) {
|
||||
var viewPath = "?view=" + $location.search().view,
|
||||
newTabPath =
|
||||
"index.html#" + urlForLocation(mode, domainObject) + viewPath;
|
||||
return newTabPath;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Returns the Url path for a specific domain object
|
||||
* without the index.html path and the view path
|
||||
* @param {value} value of the browse or edit mode
|
||||
* for the path
|
||||
* @param {DomainObject} value of the domain object
|
||||
* to get the path of
|
||||
*/
|
||||
urlForNewTab: urlForNewTab,
|
||||
/**
|
||||
* Returns the Url path for a specific domain object
|
||||
* including the index.html path and the view path
|
||||
* allowing a new tab to hold the correct characteristics
|
||||
* @param {value} value of the browse or edit mode
|
||||
* for the path
|
||||
* @param {DomainObject} value of the domain object
|
||||
* to get the path of
|
||||
*/
|
||||
urlForLocation: urlForLocation
|
||||
};
|
||||
this.$location = $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Url path for a specific domain object
|
||||
* without the index.html path and the view path
|
||||
* @param {string} mode value of browse or edit mode
|
||||
* for the path
|
||||
* @param {DomainObject} value of the domain object
|
||||
* to get the path of
|
||||
* @returns {string} URL for the domain object
|
||||
*/
|
||||
UrlService.prototype.urlForLocation = function (mode, domainObject) {
|
||||
var context = domainObject &&
|
||||
domainObject.getCapability('context'),
|
||||
objectPath = context ? context.getPath() : [],
|
||||
ids = objectPath.map(function (domainObject) {
|
||||
return domainObject.getId();
|
||||
});
|
||||
|
||||
// Parses the path together. Starts with the
|
||||
// default index.html file, then the mode passed
|
||||
// into the service, followed by ids in the url
|
||||
// joined by '/', and lastly the view path from
|
||||
// the current location
|
||||
return mode + "/" + ids.slice(1).join("/");
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the Url path for a specific domain object
|
||||
* including the index.html path and the view path
|
||||
* allowing a new tab to hold the correct characteristics
|
||||
* @param {string} mode value of browse or edit mode
|
||||
* for the path
|
||||
* @param {DomainObject} value of the domain object
|
||||
* to get the path of
|
||||
* @returns {string} URL for the domain object
|
||||
*/
|
||||
UrlService.prototype.urlForNewTab = function (mode, domainObject) {
|
||||
var viewPath = "?view=" + this.$location.search().view,
|
||||
newTabPath =
|
||||
"index.html#" + this.urlForLocation(mode, domainObject) +
|
||||
viewPath;
|
||||
return newTabPath;
|
||||
};
|
||||
|
||||
return UrlService;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
@@ -20,6 +20,13 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
/**
|
||||
* This bundle provides support for object inspection (specifically, metadata
|
||||
* show in bubbles on hover.)
|
||||
* @namespace platform/commonUI/inspect
|
||||
*/
|
||||
|
||||
define({
|
||||
BUBBLE_TEMPLATE: "<mct-container key=\"bubble\" " +
|
||||
"bubble-title=\"{{bubbleTitle}}\" " +
|
||||
@@ -33,4 +40,4 @@ define({
|
||||
// Max width and margins allowed for bubbles; defined in /platform/commonUI/general/res/sass/_constants.scss
|
||||
BUBBLE_MARGIN_LR: 10,
|
||||
BUBBLE_MAX_WIDTH: 300
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,92 +30,109 @@ define(
|
||||
* The `info` gesture displays domain object metadata in a
|
||||
* bubble on hover.
|
||||
*
|
||||
* @memberof platform/commonUI/inspect
|
||||
* @constructor
|
||||
* @implements {Gesture}
|
||||
* @param $timeout Angular's `$timeout`
|
||||
* @param {InfoService} infoService a service which shows info bubbles
|
||||
* @param {number} DELAY delay, in milliseconds, before bubble appears
|
||||
* @param {number} delay delay, in milliseconds, before bubble appears
|
||||
* @param element jqLite-wrapped DOM element
|
||||
* @param {DomainObject} domainObject the domain object for which to
|
||||
* show information
|
||||
*/
|
||||
function InfoGesture($timeout, infoService, DELAY, element, domainObject) {
|
||||
var dismissBubble,
|
||||
pendingBubble,
|
||||
mousePosition,
|
||||
scopeOff;
|
||||
function InfoGesture($timeout, infoService, delay, element, domainObject) {
|
||||
var self = this;
|
||||
|
||||
function trackPosition(event) {
|
||||
// Record mouse position, so bubble can be shown at latest
|
||||
// mouse position (not just where the mouse entered)
|
||||
mousePosition = [ event.clientX, event.clientY ];
|
||||
}
|
||||
|
||||
function hideBubble() {
|
||||
// If a bubble is showing, dismiss it
|
||||
if (dismissBubble) {
|
||||
dismissBubble();
|
||||
element.off('mouseleave', hideBubble);
|
||||
dismissBubble = undefined;
|
||||
}
|
||||
// If a bubble will be shown on a timeout, cancel that
|
||||
if (pendingBubble) {
|
||||
$timeout.cancel(pendingBubble);
|
||||
element.off('mousemove', trackPosition);
|
||||
element.off('mouseleave', hideBubble);
|
||||
pendingBubble = undefined;
|
||||
}
|
||||
// Also clear mouse position so we don't have a ton of tiny
|
||||
// arrays allocated while user mouses over things
|
||||
mousePosition = undefined;
|
||||
}
|
||||
|
||||
function showBubble(event) {
|
||||
trackPosition(event);
|
||||
|
||||
// Also need to track position during hover
|
||||
element.on('mousemove', trackPosition);
|
||||
|
||||
// Show the bubble, after a suitable delay (if mouse has
|
||||
// left before this time is up, this will be canceled.)
|
||||
pendingBubble = $timeout(function () {
|
||||
dismissBubble = infoService.display(
|
||||
"info-table",
|
||||
domainObject.getModel().name,
|
||||
domainObject.useCapability('metadata'),
|
||||
mousePosition
|
||||
);
|
||||
element.off('mousemove', trackPosition);
|
||||
pendingBubble = undefined;
|
||||
}, DELAY);
|
||||
|
||||
element.on('mouseleave', hideBubble);
|
||||
}
|
||||
|
||||
// Show bubble (on a timeout) on mouse over
|
||||
element.on('mouseenter', showBubble);
|
||||
// Callback functions to preserve the "this" pointer (in the
|
||||
// absence of Function.prototype.bind)
|
||||
this.showBubbleCallback = function (event) {
|
||||
self.showBubble(event);
|
||||
};
|
||||
this.hideBubbleCallback = function (event) {
|
||||
self.hideBubble(event);
|
||||
};
|
||||
this.trackPositionCallback = function (event) {
|
||||
self.trackPosition(event);
|
||||
};
|
||||
|
||||
// Also make sure we dismiss bubble if representation is destroyed
|
||||
// before the mouse actually leaves it
|
||||
scopeOff = element.scope().$on('$destroy', hideBubble);
|
||||
this.scopeOff = element.scope().$on('$destroy', this.hideBubbleCallback);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Detach any event handlers associated with this gesture.
|
||||
* @memberof InfoGesture
|
||||
* @method
|
||||
*/
|
||||
destroy: function () {
|
||||
// Dismiss any active bubble...
|
||||
hideBubble();
|
||||
// ...and detach listeners
|
||||
element.off('mouseenter', showBubble);
|
||||
scopeOff();
|
||||
}
|
||||
};
|
||||
this.element = element;
|
||||
this.$timeout = $timeout;
|
||||
this.infoService = infoService;
|
||||
this.delay = delay;
|
||||
this.domainObject = domainObject;
|
||||
|
||||
// Show bubble (on a timeout) on mouse over
|
||||
element.on('mouseenter', this.showBubbleCallback);
|
||||
}
|
||||
|
||||
InfoGesture.prototype.trackPosition = function (event) {
|
||||
// Record mouse position, so bubble can be shown at latest
|
||||
// mouse position (not just where the mouse entered)
|
||||
this.mousePosition = [ event.clientX, event.clientY ];
|
||||
};
|
||||
|
||||
InfoGesture.prototype.hideBubble = function () {
|
||||
// If a bubble is showing, dismiss it
|
||||
if (this.dismissBubble) {
|
||||
this.dismissBubble();
|
||||
this.element.off('mouseleave', this.hideBubbleCallback);
|
||||
this.dismissBubble = undefined;
|
||||
}
|
||||
// If a bubble will be shown on a timeout, cancel that
|
||||
if (this.pendingBubble) {
|
||||
this.$timeout.cancel(this.pendingBubble);
|
||||
this.element.off('mousemove', this.trackPositionCallback);
|
||||
this.element.off('mouseleave', this.hideBubbleCallback);
|
||||
this.pendingBubble = undefined;
|
||||
}
|
||||
// Also clear mouse position so we don't have a ton of tiny
|
||||
// arrays allocated while user mouses over things
|
||||
this.mousePosition = undefined;
|
||||
};
|
||||
|
||||
InfoGesture.prototype.showBubble = function (event) {
|
||||
var self = this;
|
||||
|
||||
this.trackPosition(event);
|
||||
|
||||
// Also need to track position during hover
|
||||
this.element.on('mousemove', this.trackPositionCallback);
|
||||
|
||||
// Show the bubble, after a suitable delay (if mouse has
|
||||
// left before this time is up, this will be canceled.)
|
||||
this.pendingBubble = this.$timeout(function () {
|
||||
self.dismissBubble = self.infoService.display(
|
||||
"info-table",
|
||||
self.domainObject.getModel().name,
|
||||
self.domainObject.useCapability('metadata'),
|
||||
self.mousePosition
|
||||
);
|
||||
self.element.off('mousemove', self.trackPositionCallback);
|
||||
self.pendingBubble = undefined;
|
||||
}, this.delay);
|
||||
|
||||
this.element.on('mouseleave', this.hideBubbleCallback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Detach any event handlers associated with this gesture.
|
||||
* @method
|
||||
*/
|
||||
InfoGesture.prototype.destroy = function () {
|
||||
// Dismiss any active bubble...
|
||||
this.hideBubble();
|
||||
// ...and detach listeners
|
||||
this.element.off('mouseenter', this.showBubbleCallback);
|
||||
this.scopeOff();
|
||||
};
|
||||
|
||||
return InfoGesture;
|
||||
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
|
||||
@@ -31,65 +31,71 @@ define(
|
||||
|
||||
/**
|
||||
* Displays informative content ("info bubbles") for the user.
|
||||
* @memberof platform/commonUI/inspect
|
||||
* @constructor
|
||||
*/
|
||||
function InfoService($compile, $document, $window, $rootScope) {
|
||||
this.$compile = $compile;
|
||||
this.$document = $document;
|
||||
this.$window = $window;
|
||||
this.$rootScope = $rootScope;
|
||||
}
|
||||
|
||||
function display(templateKey, title, content, position) {
|
||||
var body = $document.find('body'),
|
||||
scope = $rootScope.$new(),
|
||||
winDim = [$window.innerWidth, $window.innerHeight],
|
||||
bubbleSpaceLR = InfoConstants.BUBBLE_MARGIN_LR + InfoConstants.BUBBLE_MAX_WIDTH,
|
||||
goLeft = position[0] > (winDim[0] - bubbleSpaceLR),
|
||||
goUp = position[1] > (winDim[1] / 2),
|
||||
bubble;
|
||||
/**
|
||||
* Display an info bubble at the specified location.
|
||||
* @param {string} templateKey template to place in bubble
|
||||
* @param {string} title title for the bubble
|
||||
* @param {*} content content to pass to the template, via
|
||||
* `ng-model`
|
||||
* @param {number[]} x,y position of the info bubble, in
|
||||
* pixel coordinates.
|
||||
* @returns {Function} a function that may be invoked to
|
||||
* dismiss the info bubble
|
||||
*/
|
||||
InfoService.prototype.display = function (templateKey, title, content, position) {
|
||||
var $compile = this.$compile,
|
||||
$document = this.$document,
|
||||
$window = this.$window,
|
||||
$rootScope = this.$rootScope,
|
||||
body = $document.find('body'),
|
||||
scope = $rootScope.$new(),
|
||||
winDim = [$window.innerWidth, $window.innerHeight],
|
||||
bubbleSpaceLR = InfoConstants.BUBBLE_MARGIN_LR + InfoConstants.BUBBLE_MAX_WIDTH,
|
||||
goLeft = position[0] > (winDim[0] - bubbleSpaceLR),
|
||||
goUp = position[1] > (winDim[1] / 2),
|
||||
bubble;
|
||||
|
||||
// Pass model & container parameters into the scope
|
||||
scope.bubbleModel = content;
|
||||
scope.bubbleTemplate = templateKey;
|
||||
scope.bubbleLayout = (goUp ? 'arw-btm' : 'arw-top') + ' ' +
|
||||
(goLeft ? 'arw-right' : 'arw-left');
|
||||
scope.bubbleTitle = title;
|
||||
// Pass model & container parameters into the scope
|
||||
scope.bubbleModel = content;
|
||||
scope.bubbleTemplate = templateKey;
|
||||
scope.bubbleLayout = (goUp ? 'arw-btm' : 'arw-top') + ' ' +
|
||||
(goLeft ? 'arw-right' : 'arw-left');
|
||||
scope.bubbleTitle = title;
|
||||
|
||||
// Create the context menu
|
||||
bubble = $compile(BUBBLE_TEMPLATE)(scope);
|
||||
// Create the context menu
|
||||
bubble = $compile(BUBBLE_TEMPLATE)(scope);
|
||||
|
||||
// Position the bubble
|
||||
bubble.css('position', 'absolute');
|
||||
if (goLeft) {
|
||||
bubble.css('right', (winDim[0] - position[0] + OFFSET[0]) + 'px');
|
||||
} else {
|
||||
bubble.css('left', position[0] + OFFSET[0] + 'px');
|
||||
}
|
||||
if (goUp) {
|
||||
bubble.css('bottom', (winDim[1] - position[1] + OFFSET[1]) + 'px');
|
||||
} else {
|
||||
bubble.css('top', position[1] + OFFSET[1] + 'px');
|
||||
}
|
||||
|
||||
// Add the menu to the body
|
||||
body.append(bubble);
|
||||
|
||||
// Return a function to dismiss the bubble
|
||||
return function () { bubble.remove(); };
|
||||
// Position the bubble
|
||||
bubble.css('position', 'absolute');
|
||||
if (goLeft) {
|
||||
bubble.css('right', (winDim[0] - position[0] + OFFSET[0]) + 'px');
|
||||
} else {
|
||||
bubble.css('left', position[0] + OFFSET[0] + 'px');
|
||||
}
|
||||
if (goUp) {
|
||||
bubble.css('bottom', (winDim[1] - position[1] + OFFSET[1]) + 'px');
|
||||
} else {
|
||||
bubble.css('top', position[1] + OFFSET[1] + 'px');
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Display an info bubble at the specified location.
|
||||
* @param {string} templateKey template to place in bubble
|
||||
* @param {string} title title for the bubble
|
||||
* @param {*} content content to pass to the template, via
|
||||
* `ng-model`
|
||||
* @param {number[]} x,y position of the info bubble, in
|
||||
* pixel coordinates.
|
||||
* @returns {Function} a function that may be invoked to
|
||||
* dismiss the info bubble
|
||||
*/
|
||||
display: display
|
||||
};
|
||||
}
|
||||
// Add the menu to the body
|
||||
body.append(bubble);
|
||||
|
||||
// Return a function to dismiss the bubble
|
||||
return function () { bubble.remove(); };
|
||||
};
|
||||
|
||||
return InfoService;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user