wire up show source service to button

This commit is contained in:
lawson89 2014-08-25 09:47:57 -04:00
parent 48c31458aa
commit 53b6c16fb6
2 changed files with 99 additions and 34 deletions

View File

@ -74,7 +74,7 @@
<button type="button" class="btn btn-primary btn-sm">Params/Cookies</button> <button type="button" class="btn btn-primary btn-sm">Params/Cookies</button>
<button type="button" class="btn btn-primary btn-sm">Hints</button> <button type="button" class="btn btn-primary btn-sm">Hints</button>
<button type="button" class="btn btn-primary btn-sm">Lesson Plan</button> <button type="button" class="btn btn-primary btn-sm">Lesson Plan</button>
<button type="button" class="btn btn-primary btn-sm">Java [Source]</button> <button type="button" class="btn btn-primary btn-sm" ng-click="showSource('lg')">Java [Source]</button>
<button type="button" class="btn btn-primary btn-sm">Solution</button> <button type="button" class="btn btn-primary btn-sm">Solution</button>
</div><!--toggle navigation end--> </div><!--toggle navigation end-->
</header> </header>
@ -115,7 +115,7 @@
</div> </div>
</div> </div>
<!--
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<h4>Lesson Source Code</h4> <h4>Lesson Source Code</h4>
@ -126,6 +126,7 @@
</div> </div>
</div> </div>
</div> </div>
-->
</section> </section>
</section> </section>
@ -133,7 +134,6 @@
</section> </section>
<!-- <script src="plugins/waypoints/waypoints.min.js"></script> --> <!-- <script src="plugins/waypoints/waypoints.min.js"></script> -->
<!-- <script src="js/application.js"></script> --> <!-- <script src="js/application.js"></script> -->
@ -216,4 +216,21 @@
</script> </script>
</body> </body>
<!-- Modals -->
<script type="text/ng-template" id="showSource.html">
<div class="modal-header">
<button class="btn btn-primary pull-right" ng-click="ok()">Close</button>
<h3 class="modal-title">Lesson Source</h3>
</div>
<div class="modal-body">
<pre>{{lessonSource}}</pre>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">Close</button>
</div>
</script>
</html> </html>

View File

@ -6,7 +6,7 @@
/** Menu Controller /** Menu Controller
* prepares and updates menu topic items for the view * prepares and updates menu topic items for the view
*/ */
goat.controller('goatLesson', function($scope, $http) { goat.controller('goatLesson', function($scope, $http, $modal, $log) {
//TODO: implement via separate promise and use config for menu //TODO: implement via separate promise and use config for menu
$http({method: 'GET', url: 'service/lessonmenu.mvc'}).then( $http({method: 'GET', url: 'service/lessonmenu.mvc'}).then(
function(menuData) { function(menuData) {
@ -33,17 +33,50 @@ goat.controller('goatLesson', function($scope, $http) {
} }
} }
); );
/*
console.log("Updating Lesson Source..."); console.log("Updating Lesson Source...");
$http.get('service/source.mvc').success( function(data){ $http.get('service/source.mvc').success(function(data) {
$scope.lessonSource = data.source; $scope.lessonSource = data.source;
}).error( function(data){ }).error(function(data) {
$scope.lessonSource = data.message; $scope.lessonSource = data.message;
console.log("LessonSource = '" + data.message + "'"); console.log("LessonSource = '" + data.message + "'");
}) });
*/
}; };
}) /*
.animation('.slideDown', function() { * Function to load lesson source
* @returns {undefined}
*/
$scope.showSource = function(size) {
// fetch source from web service
$http.get('service/source.mvc').success(function(data) {
$scope.lessonSource = data.source;
$scope.openSourceModal(size);
}).error(function(data) {
$scope.lessonSource = data.message;
console.log("LessonSource = '" + data.message + "'");
$scope.openSourceModal(size);
})
}
$scope.openSourceModal = function(size) {
var modalInstance = $modal.open({
templateUrl: 'showSource.html',
controller: showSourceController,
size: size,
resolve: {
lessonSource: function() {
return $scope.lessonSource;
}
}
});
modalInstance.result.then(function() {
$log.info('Modal dismissed at: ' + new Date());
});
}
}).animation('.slideDown', function() {
var NgHideClassName = 'ng-hide'; var NgHideClassName = 'ng-hide';
return { return {
beforeAddClass: function(element, className, done) { beforeAddClass: function(element, className, done) {
@ -57,7 +90,7 @@ goat.controller('goatLesson', function($scope, $http) {
} }
} }
} }
}); });
//TODO add recursion to handle arr[i].children objects //TODO add recursion to handle arr[i].children objects
@ -80,7 +113,7 @@ goat.addMenuClasses = function(arr) {
function loadLessonContent(_url) { function loadLessonContent(_url) {
//TODO: switch to $http (angular) later //TODO: switch to $http (angular) later
//return $http({method:'GET', url: _url}); //return $http({method:'GET', url: _url});
return $.get(_url,{},null,"html"); return $.get(_url, {}, null, "html");
} }
@ -88,4 +121,19 @@ function loadMenuData() {
return $http({method: 'GET', url: 'service/lessonmenu.mvc'}); return $http({method: 'GET', url: 'service/lessonmenu.mvc'});
} }
/* Controllers for modal instances */
var showSourceController = function($scope, $modalInstance, lessonSource) {
$scope.lessonSource = lessonSource;
$scope.ok = function() {
$modalInstance.close();
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};