Created
January 11, 2014 16:07
-
-
Save andybak/8372767 to your computer and use it in GitHub Desktop.
You have failed me for the final time, brain.
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
<div id='BookingCtrl' ng-controller="BookingCtrl"> | |
<div id='StockListCtrl' ng-controller="StockListCtrl"> | |
<h1>Status: {{ booking().status }} Chargeable days: {{ booking().chargeable_days }}</h1> | |
<section class="timeline-stock light clearfix"> | |
<header class="timeline-header clearfix"> | |
<div id="form-booking"> | |
<div class="input-pair"><label for="hire-start">Est. Delivery</label><input name="hire-start" class="text lg" type="datetime-local" value="{{ booking().estimated_dispatch }}"></div> | |
<div class="input-pair"><label for="hire-end">Est. Collection</label><input name="hire-end" class="text lg" type="datetime-local" value="{{ booking().estimated_return }}"></div> | |
<button id="refresh-hire-period" class="button action lg"><i class="fa fa-refresh fa-lg"></i></button> | |
<div class="search-wrapper"> | |
<form ng-submit='stockItems.search(search_term)'> | |
<input ng-model='search_term' type="search" class="input-search lg" placeholder="Search inventory" autofocus="true"> | |
<button type="submit" id="search-button" class="button action lg"><i class="fa fa-search fa-lg"></i></button> | |
</form> | |
</div> | |
</div> | |
</header> | |
<div class="window"> | |
<div ng-controller="TimeBlockCtrl" class="timeline clearfix"> | |
<div class="time-block" ng-repeat="date in dateRange(booking())"><span class="label">{{ date }}</span></div> | |
<span class="hire-period" style="width: 660px; left: 48px;"></span> | |
</div> | |
<div class="items"> | |
<div ng-repeat="stock_item in stockItems.items" class="item {{ stock_item.type }} clearfix"> | |
<header class="item-header"> | |
<ul class="item-actions"> | |
<li class="action"><input class="qty sm" type="text" placeholder="1"><button class="button add" title="Add item">+</button></li> | |
</ul> | |
<span class="item-name" title="{{ stock_item.label }} - {{ stock_item.item_model.name }}"><span class="item-code">{{ stock_item.label }}</span> {{ stock_item.item_model.name }} <span class="stock">(6/13)</span> <button class="info" title="Show information">i</button></span> | |
</header> | |
<div class="row"> | |
<div ng-repeat="segment in stock_item.segments" class="segment" style="width: {{ segment.duration }}px;"> | |
<div class="overlay {% if segment.stock_level == 0 %}unavailable{% endif %}"><span class="label">{{ segment.stock_level }}</span></div> | |
</div> | |
</div> | |
</div> | |
<div ng-show="!stockItems.items.length"><h1>There are no items</h1></div> | |
</div> | |
</div> | |
</section> | |
<h2>Secured Items</h2> | |
<section id="section-staging" class="clearfix"> | |
<table> | |
<thead> | |
<tr> | |
<th class="qty-standard">Hire</th> | |
<th class="qty-crosshired">X-Hire <button class="info" title="Items are automatically crosshired when no stock is available internally. Crosshired items appear in the crosshire list.">i</button></th> | |
<th class="name">Item</th> | |
<th class="specify">Choice <button class="info" title="Choices allow you to flag whether the customer requires that specific item, just the model or will even accept an equivalent. This can help with re-organising bookings in order to meet the needs of a future customer with more specific requirements.">i</button></th> | |
<th class="day">Day</th> | |
<th class="week">Week <button class="info" title="A week is counted as 7 days. Each block of 7 days will be priced at the weekly rate. Any remaining days will be priced at the daily rate.">i</button></th> | |
<th class="days">Days</th> | |
<th class="days">Discount</th> | |
<th class="total">Total</th> | |
<th class="actions"></th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr ng-repeat="item in booking().booking_stock_items" class="{{ item.stock_item.item_model.type }}"> | |
<td class="number"><span class="qty-standard number">{{ item.quantity }}</span></td> | |
<td class="number"><span class="qty-crosshired number">0</span></td> | |
<td><span class="name"><span class="item-code"><i class="fa fa-barcode"></i> {{ item.stock_item.label }}</span> {{ item.stock_item.item_model.name }}</span></td> | |
<td> | |
<select name="swap" id=""> | |
<option value="test">This model</option> | |
<option value="test">This or alternative</option> | |
<option value="test">This or alternative</option> | |
</select> | |
</td> | |
<td class="number"><span class="item-day-rate number">£ {{ item.stock_item.item_model.daily_rate }}</span></td> | |
<td class="number"><span class="item-week-rate number">£ {{ item.stock_item.item_model.weekly_rate }}</span></td> | |
<td class="number"><span class="chargeable-days">{{ booking().chargeable_days }}</span></td> | |
<td class="number"><span class="item-discount number"><input class="override-rate" type="text" value="{{ item.discount }}"></input>% <a class="reset">reset</a></span></td> | |
<td class="number"><span class="item-total number">£{{ item.price }}</span></td> | |
<td><span class="actions"><button class="button remove" title="Remove Item">x</button></span></td> | |
</tr> | |
</tbody> | |
</table> | |
</section> | |
</div> | |
</div> |
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
var stockApp = angular.module('stockApp', [ | |
'ngResource', | |
]); | |
stockApp.factory('currentBooking', ['Booking', function(Booking) { | |
var currentBooking = { | |
bookingId: null, | |
booking: null, | |
start: null, | |
end: null, | |
setBookingId: function (bookingId) { | |
var _this = this; | |
if (bookingId === this.bookingId) return; | |
this.bookingId = bookingId; | |
var booking = Booking.get({id: currentBooking.bookingId}, function() { | |
var start = new Date(booking.leaves_stock); | |
var end = new Date(booking.returns_to_stock); | |
start.setDate(start.getDate() - 1); | |
end.setDate(end.getDate() - 1); | |
_this.start = start; | |
_this.end = end; | |
_this.booking = booking; | |
}); | |
} | |
}; | |
// Initialised from variable preloaded in page | |
currentBooking.setBookingId(BOOKING_ID); | |
return currentBooking; | |
}]); | |
stockApp.controller('BookingCtrl', ['$scope', '$http', 'currentBooking', 'Booking', | |
function($scope, currentBooking) { | |
$scope.currentBooking = currentBooking; | |
$scope.booking = function () { return currentBooking.booking }; | |
} | |
]); | |
stockApp.controller('TimeBlockCtrl', ['$scope', | |
function ($scope) { | |
$scope.dateRange = function(booking){ | |
var input = []; | |
var start = $scope.start; | |
var end = $scope.end; | |
for (var i=start; i<=end; i.setDate(i.getDate() + 1)) { | |
input.push(i.getDate()+'/'+ (i.getMonth() + 1)); | |
} | |
return input; | |
}; | |
} | |
]); | |
stockApp.controller('StockListCtrl', ['$scope', 'StockItems', 'currentBooking', | |
function($scope, StockItems, currentBooking) { | |
$scope.stockItems = StockItems; | |
StockItems.currentBooking = currentBooking; | |
} | |
]); | |
stockApp.factory('Booking', ['$resource', function($resource) { | |
return $resource('/api/booking/:id', null, { | |
"update": {method: "PUT"} | |
}); | |
}]); | |
stockApp.factory('StockItems', function ($http) { | |
return { | |
items: [], | |
currentBooking: null, | |
search: function (query) { | |
var self = this; | |
self.items = []; | |
$http.get('/api/stock_item/?search=' + query).success(function(data) { | |
data.results.forEach(function (stock_item) { | |
self.items.push(stock_item); | |
var id = stock_item.url.split('/'); | |
id = id[id.length-2]; | |
if (self.currentBooking.bookingId) { | |
$http.get('/api/stock_item/' + id + '/get_segments_for_booking/?booking=' + self.currentBooking.bookingId) | |
.success(function (data) { | |
stock_item.segments = data.segments; | |
}); | |
} | |
}); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment