Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit c0215c8

Browse files
chore(build): update custom build to use $modal service
Closes #927
1 parent 9aecd4e commit c0215c8

File tree

2 files changed

+50
-37
lines changed

2 files changed

+50
-37
lines changed

Diff for: misc/demo/assets/app.js

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1-
21
angular.module('bootstrapDemoApp', ['ui.bootstrap', 'plunker']);
32

4-
function MainCtrl($scope, $http, $document, orderByFilter) {
3+
function MainCtrl($scope, $http, $document, $modal, orderByFilter) {
54
var url = "http://50.116.42.77:3001";
6-
$scope.selectedModules = [];
75
//iFrame for downloading
86
var $iframe = angular.element('<iframe>').css('display','none');
97
$document.find('body').append($iframe);
108

119
$scope.showBuildModal = function() {
12-
$scope.buildModalShown = true;
13-
//Load modules if they aren't loaded yet
14-
if (!$scope.modules) {
15-
$http.get(url + "/api/bootstrap").then(function(response) {
16-
$scope.modules = response.data.modules;
17-
}, function() {
18-
$scope.buildGetErrorText = "Error retrieving build files from server.";
19-
});
20-
}
21-
};
10+
var modalInstance = $modal.open({
11+
templateUrl: 'buildModal.html',
12+
controller: 'SelectModulesCtrl',
13+
resolve: {
14+
modules: function() {
15+
return $http.get(url + "/api/bootstrap").then(function(response) {
16+
return response.data.modules;
17+
});
18+
}
19+
}
20+
});
2221

23-
$scope.downloadBuild = function() {
24-
var downloadUrl = url + "/api/bootstrap/download?";
25-
angular.forEach($scope.selectedModules, function(module) {
26-
downloadUrl += "modules=" + module + "&";
22+
modalInstance.result.then(function(selectedModules) {
23+
var downloadUrl = url + "/api/bootstrap/download?";
24+
angular.forEach(selectedModules, function(module) {
25+
downloadUrl += "modules=" + module + "&";
26+
});
27+
$iframe.attr('src','');
28+
$iframe.attr('src', downloadUrl);
2729
});
28-
$iframe.attr('src','');
29-
$iframe.attr('src', downloadUrl);
30-
$scope.buildModalShown = false;
3130
};
31+
}
32+
33+
var SelectModulesCtrl = function($scope, $modalInstance, modules) {
34+
35+
$scope.selectedModules = [];
36+
$scope.modules = modules;
3237

3338
$scope.selectedChanged = function(module, selected) {
3439
if (selected) {
@@ -37,4 +42,12 @@ function MainCtrl($scope, $http, $document, orderByFilter) {
3742
$scope.selectedModules.splice($scope.selectedModules.indexOf(module), 1);
3843
}
3944
};
40-
}
45+
46+
$scope.downloadBuild = function () {
47+
$modalInstance.close($scope.selectedModules);
48+
};
49+
50+
$scope.cancel = function () {
51+
$modalInstance.dismiss();
52+
};
53+
};

Diff for: misc/demo/index.html

+16-16
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,24 @@ <h1><%= module.displayName %><small>
218218
<script src="assets/rainbow-generic.js"></script>
219219
<script src="assets/rainbow-javascript.js"></script>
220220
<script src="assets/rainbow-html.js"></script>
221-
<div modal="buildModalShown" class="fade">
222-
<div class="modal-header"><h2>Create a Custom Build</h2></div>
223-
<div class="modal-body">
224-
<div ng-show="buildErrorText">
225-
<h3 style="text-align: center;">{{buildErrorText}}</h3>
221+
<script type="text/ng-template" id="buildModal.html">
222+
<div class="modal-header"><h2>Create a Custom Build</h2></div>
223+
<div class="modal-body">
224+
<div ng-show="buildErrorText">
225+
<h3 style="text-align: center;">{{buildErrorText}}</h3>
226+
</div>
227+
<div ng-hide="buildErrorText">
228+
<label>Select the modules you wish to download:</label>
229+
<% modules.forEach(function(module) { %>
230+
<button type="button" class="btn" ng-class="{'btn-primary': module.<%= module.name %>}" style="width: 170px; margin-bottom: 3px;" ng-model="module.<%= module.name %>" btn-checkbox ng-change="selectedChanged('<%= module.name %>', module.<%= module.name %>)"><%= module.displayName %></button>
231+
<% }); %>
232+
</div>
226233
</div>
227-
<div ng-hide="buildErrorText">
228-
<label>Select the modules you wish to download:</label>
229-
<% modules.forEach(function(module) { %>
230-
<button type="button" class="btn" ng-class="{'btn-primary': module.<%= module.name %>}" style="width: 170px; margin-bottom: 3px;" ng-model="module.<%= module.name %>" btn-checkbox ng-change="selectedChanged('<%= module.name %>', module.<%= module.name %>)"><%= module.displayName %></button>
231-
<% }); %>
234+
<div class="modal-footer">
235+
<a class="btn btn-primary" ng-disabled="!selectedModules.length" ng-click="selectedModules.length && downloadBuild()"><i class="icon-download-alt icon-white"></i> Download {{selectedModules.length}} Modules</a>
236+
<a class="btn" ng-click="cancel()">Cancel</a>
232237
</div>
233-
</div>
234-
<div class="modal-footer">
235-
<a class="btn btn-primary" ng-disabled="!selectedModules.length" ng-click="selectedModules.length && downloadBuild()"><i class="icon-download-alt icon-white"></i> Download {{selectedModules.length}} Modules</a>
236-
<a class="btn" ng-click="buildModalShown = false">Cancel</a>
237-
</div>
238-
</div>
238+
</script>
239239

240240
<script type="text/javascript">
241241

0 commit comments

Comments
 (0)