Created
September 25, 2013 20:33
-
-
Save ianjosephwilson/6705618 to your computer and use it in GitHub Desktop.
This file contains 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
define([], function() { | |
'use strict'; | |
return function ($scope, $http, $routeParams, $q, $location) { | |
var warehouseId = $routeParams.warehouseId, | |
warehouseDeferred = $q.defer(), | |
locationsDeferred = $q.defer(); | |
// @TODO: Resolve these. | |
$scope.crumbs = []; | |
$scope.warehouse = warehouseDeferred.promise; | |
$scope.locations = locationsDeferred.promise; | |
$scope.inventory = { | |
locationLines: [], | |
featureLines: [] | |
}; | |
$scope.addLocation = function () { | |
$scope.inventory.locationLines.push({ | |
location: '' | |
}); | |
}; | |
$scope.removeLocation = function(index) { | |
$scope.inventory.locationLines.splice(index, 1); | |
}; | |
$scope.addFeature = function () { | |
$scope.inventory.featureLines.push({ | |
location: '' | |
}); | |
}; | |
$scope.removeFeature = function(index) { | |
$scope.inventory.featureLines.splice(index, 1); | |
}; | |
$scope.getFeatures = function (viewValue) { | |
return $http.get('/admin/inventory/api/features', { | |
params: { | |
name: viewValue, | |
limit: 20 | |
} | |
}).then(function (httpResult) { | |
return httpResult.data.features; | |
}, function () { | |
return []; | |
}); | |
}; | |
$scope.createInventory = function () { | |
return $http.post('/admin/inventory/api/create', { | |
params: { | |
warehouseId: $scope.warehouse.id, | |
locationIds: $scope.inventory.locationLines.map(function (value) { | |
if (value.location) { | |
return value.location.id; | |
} | |
}), | |
featureIds: $scope.inventory.featureLines.map(function (value) { | |
if (value.feature) { | |
return value.feature.id; | |
} | |
}) | |
} | |
}).then(function (httpResult) { | |
// Load the edit inventory view. | |
$location.path('/admin/inventory/edit/' + httpResult.data.inventoryId); | |
}, function () { | |
// @TODO | |
window.console.log('Failed to create inventory'); | |
}); | |
}; | |
// | |
// Initialize the page. | |
// | |
window.console.log('Calling get'); | |
$http.get('/admin/inventory/api/new/' + warehouseId, {}).then(function ( | |
httpResult) { | |
window.console.log('Got results', httpResult.data); | |
warehouseDeferred.resolve(httpResult.data.warehouse); | |
locationsDeferred.resolve(httpResult.data.locations); | |
}); | |
}; | |
}); |
This file contains 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
<form name="newInventoryForm" novalidate class="form-inline"> | |
<div> | |
{{warehouse|json}} | |
{{locations|json}} | |
Warehouse: {{warehouse.name}} | |
<input type="submit" ng-click="createInventory()" ng-disabled="newInventoryForm.$invalid" valud="Create Inventory"> | |
</div> | |
<div>Locations <button ng-click="addLocation()">add</button></div> | |
<div ng-repeat="line in inventory.locationLines"> | |
<input placeholder="location" tabindex="4" class="input-small" required | |
ng-model="line.location" | |
typeahead-editable="false" | |
typeahead="location as location.name for location in locations | filter:$viewValue"> | |
<button ng-click="removeLocation($index)">remove</button> | |
</div> | |
<div>Features <button ng-click="addFeature()">add</button></div> | |
<div ng-repeat="line in inventory.featureLines"> | |
<input placeholder="feature" tabindex="4" class="input-small" required | |
autocomplete="off" | |
ng-model="line.feature" | |
typeahead-editable="false" | |
typeahead-wait-ms="200" | |
typeahead-min-length="3" | |
typeahead="feature as feature.name for feature in getFeatures($viewValue)"> | |
<button ng-click="removeFeature($index)">remove</button> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment