[Common UI] Initial commonUI bundles
Bring in work on general-purpose and over-arching user interface bundles from the sandbox transition branch. WTD-574.
This commit is contained in:
17
platform/commonUI/dialog/bundle.json
Normal file
17
platform/commonUI/dialog/bundle.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extensions": {
|
||||
"services": [
|
||||
{
|
||||
"key": "dialogService",
|
||||
"implementation": "DialogService.js",
|
||||
"depends": [ "$document", "$compile", "$rootScope", "$timeout", "$q", "$log" ]
|
||||
}
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
"key": "overlay-dialog",
|
||||
"templateUrl": "templates/overlay.html"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
28
platform/commonUI/dialog/res/templates/overlay.html
Normal file
28
platform/commonUI/dialog/res/templates/overlay.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<div class="abs overlay" ng-show="ngModel.visible">
|
||||
<div class="abs blocker"></div>
|
||||
<div class="abs holder">
|
||||
<a href=""
|
||||
ng-click="state.cancel()"
|
||||
class="btn normal outline ui-symbol close">x</a>
|
||||
<div class="abs contents">
|
||||
<div class="abs top-bar">
|
||||
<div class="title">{{ngModel.title}}</div>
|
||||
<div class="hint">All fields marked <span class="ui-symbol req">*</span> are required.</div>
|
||||
</div>
|
||||
<div class="abs form outline editor">
|
||||
<div class='abs contents'>
|
||||
<!-- mct-include key="'form'" ng-model="" -->
|
||||
<textarea ng-model="ngModel.value"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="abs bottom-bar">
|
||||
<a class='btn lg major' href='' ng-click="ngModel.confirm()">
|
||||
OK
|
||||
</a>
|
||||
<a class='btn lg subtle' href='' ng-click="ngModel.cancel()">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
79
platform/commonUI/dialog/src/DialogService.js
Normal file
79
platform/commonUI/dialog/src/DialogService.js
Normal file
@@ -0,0 +1,79 @@
|
||||
/*global define,Promise*/
|
||||
|
||||
/**
|
||||
* Module defining DialogService. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function DialogService($document, $compile, $rootScope, $timeout, $q, $log) {
|
||||
var scope;
|
||||
|
||||
function addContent() {
|
||||
scope = $rootScope.$new();
|
||||
$document.find('body').prepend(
|
||||
$compile(
|
||||
"<mct-include ng-model=\"dialog\" key=\"'overlay-dialog'\"></mct-include>"
|
||||
)(scope)
|
||||
);
|
||||
scope.dialog = { visible: false, value: {} };
|
||||
}
|
||||
|
||||
function dismiss() {
|
||||
scope.dialog = { visible: false, value: {} };
|
||||
}
|
||||
|
||||
return {
|
||||
getUserInput: function (formModel, value) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
if (!scope) {
|
||||
addContent();
|
||||
}
|
||||
|
||||
$timeout(function () {
|
||||
if (scope.dialog.visible) {
|
||||
$log.warn([
|
||||
"Dialog already showing; ",
|
||||
"unable to show ",
|
||||
title
|
||||
].join(""));
|
||||
}
|
||||
|
||||
scope.dialog.visible = true;
|
||||
scope.dialog.title = formModel.name;
|
||||
scope.dialog.message = formModel.message;
|
||||
scope.dialog.formModel = formModel;
|
||||
scope.dialog.value = JSON.stringify(value);
|
||||
|
||||
scope.dialog.confirm = function () {
|
||||
var resultingValue;
|
||||
|
||||
try {
|
||||
resultingValue = JSON.parse(scope.dialog.value);
|
||||
} catch (e) {
|
||||
resultingValue = {};
|
||||
}
|
||||
deferred.resolve(resultingValue);
|
||||
dismiss();
|
||||
};
|
||||
scope.dialog.cancel = function () {
|
||||
deferred.reject();
|
||||
dismiss();
|
||||
};
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return DialogService;
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user