Created
September 2, 2014 05:45
-
-
Save justsml/073bda9fa3c0d984cc7b to your computer and use it in GitHub Desktop.
Commitment Viewer & Edit Page w/ Jade, AngularJS, angular-route
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div.well.commitment-modal | |
div.panel.panel-success | |
div.panel-heading | |
h2.panel-title Commitment Overview | |
div.panel-body |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compiled: | |
'use strict'; | |
var app = angular.module('app', ['trNgGrid', 'ngRoute']); | |
'use strict'; | |
app.controller('commitmentController', ['$scope', '$http', '$document', function ($scope, $http, $document) { | |
// NOTE: Testing, stuff moved to controller, ick... | |
// NOTE: Testing, stuff moved to controller, ick... | |
$scope.results = []; | |
$scope.lineBreakText = function (txt) { | |
return txt.replace(/, /g, '<br />'); | |
}; | |
// console.log("commitmentController", arguments); | |
$scope.onDataNeeded = function() { | |
$http({'url': '/admin/commitments/', method: 'GET'}) | |
.success(function(data) { | |
console.log(arguments); | |
$scope.results = data.results; | |
}) | |
.error(function(data, status) { | |
console.error("ERROR", arguments); | |
$scope.data = data || "Request failed"; | |
$scope.results = []; | |
}); | |
}; | |
$scope.delete = function(obj) { | |
console.log("Commitment: ", obj); | |
$http.put({'url': obj._id + '/', 'method': 'DELETE', 'data': obj}) | |
.success(function success(data, status, headers) { | |
console.log(arguments); | |
$scope.commitment = data; | |
$scope.status = status; | |
}) | |
.error(function(data, status) { | |
console.log(arguments); | |
$scope.data = data || "Request failed"; | |
}); | |
}; | |
$scope.query = ''; | |
$scope.limit = 20; | |
$scope.sort = ''; | |
$scope.onDataNeeded(); | |
}]); | |
app.controller('commitmentEdit', ['$scope', '$routeParams', '$location', '$http', | |
// NOTE: Testing, stuff moved to controller, ick... | |
// NOTE: Testing, stuff moved to controller, ick... | |
function($scope, $routeParams, $location, $http) { | |
console.log("commitmentEdit", arguments); | |
$scope.id = $routeParams.id; | |
$scope.isNew = $location.url().indexOf('new') !== -1; | |
$scope.edit = !$scope.isNew; | |
$scope.save = function(data) { | |
var index = $scope.results.indexOf(data); | |
console.log("Commitment: ", $scope.commitment); | |
$http({'url': $location.path(), 'method': $scope.isNew ? 'POST' : 'PUT', 'data': data}). | |
success(function success(data, status, headers) { | |
console.log("success - updated"); | |
$scope.commitment = data; | |
$scope.status = status; | |
}). | |
error(function(data, status) { | |
console.log("success - updated"); | |
$scope.data = data || "Request failed"; | |
$scope.status = status; | |
}); | |
}; | |
} | |
]); | |
'use strict'; | |
app.config(['$routeProvider', '$locationProvider', | |
function($routeProvider, $locationProvider) { | |
$routeProvider | |
.when('/admin/commitments/new', { | |
templateUrl: '/views/admin/commitments/edit.html', | |
controller: 'commitmentEdit' | |
}) | |
.when('/admin/commitments/:id/', { | |
templateUrl: '/views/admin/commitments/edit.html', | |
controller: 'commitmentEdit' | |
}) | |
.when('/admin/commitments/', { | |
templateUrl: '/views/admin/commitments/results.html', | |
controller: 'commitmentController' | |
}) | |
.otherwise({ | |
redirectTo: '/admin/commitments/' | |
}); | |
console.log("$routeProvider", $routeProvider); | |
// configure html5 to get links working on jsfiddle | |
$locationProvider.html5Mode(true); | |
}]); | |
app.filter('address', function() { | |
return function(input) { | |
return input ? input.replace(/, /g, ',<br />\r\n') : ''; | |
}; | |
}); | |
//# sourceMappingURL=ng-app.js.map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table(tr-ng-grid='', filter-by='query', items='results') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends ../../../layouts/admin | |
block head | |
title Commitments | |
block neck | |
link(rel='stylesheet', href='/views/admin/commitments/index.min.css?#{cacheBreaker}') | |
block feet | |
script(src='/views/admin/commitments/ng-app.js?#{cacheBreaker}') | |
block body | |
div(ng-controller="commitmentController") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment