-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dynamo_Client_Store_web_store.war_shared_js_viewModels_orderHistoryViewModel.js.html
executable file
·291 lines (247 loc) · 18.1 KB
/
Dynamo_Client_Store_web_store.war_shared_js_viewModels_orderHistoryViewModel.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: Dynamo/Client/Store/web/store.war/shared/js/viewModels/orderHistoryViewModel.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: Dynamo/Client/Store/web/store.war/shared/js/viewModels/orderHistoryViewModel.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/**
* @fileoverview Order History View Model.
*/
define(
//-------------------------------------------------------------------
// PACKAGE NAME
//-------------------------------------------------------------------
'viewModels/orderHistoryViewModel',
//-------------------------------------------------------------------
// DEPENDENCIES
//-------------------------------------------------------------------
['knockout', 'paginated', 'pubsub', 'ccRestClient', 'ccConstants',
'CCi18n','spinner','ccNumber'],
function(ko, Paginated, pubsub, ccRestClient, CCConstants, CCi18n, spinner, ccNumber) {
"use strict";
//-------------------------------------------------------
// View Model
//-------------------------------------------------------
/**
* OrderHistoryViewModel. Order history view model,
* used when handling order collections.
*
* @public
* @class
* @name OrderHistoryViewModel
* @extends ccPaginated
*
* @property {observable<boolean>} display=true Display results?
* @property {observable<string>} spanClass='col-md-3' The Bootstrap CSS class, determined by the viewport type.
* @property {string} type='ProductListingViewModel' View model type.
* @property {Object} orderHistoryLoadingOptions The options for the 'loading' spinner.
* @property {integer} itemsPerPage=12 The number of items per page.
* @property {integer} blockSize=12 The number of items per block.
* @property {observable<integer>} recordsPerPage=20 The number of records per page;
* @property {observable<integer>} itemsPerRow=4 The number of items per row.
* @property {integer} itemsPerRowInTabletView=4 The number of items per row in tablet view.
* @property {integer} itemsPerRowInPhoneView=2 The number of items per row in phone view.
* @property {integer} itemsPerRowInDesktopView=4 The number of items per row in desktop view.
* @property {integer} itemsPerRowInLargeDesktopView=4 The number of items per row in large desktop view.
*/
function OrderHistoryViewModel() {
var self = this;
// call super constructor
Paginated.call(this);
self.display = ko.observable(true);
// additional public variables
self.type = "OrderHistoryViewModel";
self.spanClass = ko.observable("col-md-3");
// overwrite public methods
this.orderHistoryLoadingOptions = {};
this.orderHistoryLoadingOptions.parent = '#cc-orderHistory-spinner';
this.orderHistoryLoadingOptions.selector = '#cc-orderHistory-spinner-area';
this.removeSpinner = function() {
var removeDelay = setTimeout(function() {
$('#cc-orderHistory-spinner-area').find('.cc-spinner').remove();}, 500);
};
this.itemsPerPage = 20;
this.blockSize = 20;
this.recordsPerPage = ko.observable(20);
/**
* Scroll handler method used in phone and tablet modes.
*
* Method gets next set of orders once bottom of order history
* element comes into view.
* @private
* @param {Object} eventData The event object.
*/
var scrollHandler = function(eventData) {
var scrollTop = $(window).scrollTop();
var viewportHeight = $(window).height();
if ((scrollTop + viewportHeight) >= (($(document).height() / 5) * 4)) {
self.incrementPage();
}
};
/**
* Checks the size of the current viewport and sets the viewport
* mode accordingly.
* @private
* @param {integer} viewportWidth The width of the viewport.
*/
this.checkResponsiveFeatures = function(viewportWidth) {
if (viewportWidth > CCConstants.VIEWPORT_LARGE_DESKTOP_LOWER_WIDTH) {
if (self.viewportMode() != CCConstants.LARGE_DESKTOP_VIEW) {
self.viewportMode(CCConstants.LARGE_DESKTOP_VIEW);
}
} else if (viewportWidth > CCConstants.VIEWPORT_TABLET_UPPER_WIDTH && viewportWidth <= CCConstants.VIEWPORT_LARGE_DESKTOP_LOWER_WIDTH) {
if (self.viewportMode() != CCConstants.DESKTOP_VIEW) {
self.viewportMode(CCConstants.DESKTOP_VIEW);
}
} else if (viewportWidth >= CCConstants.VIEWPORT_TABLET_LOWER_WIDTH && viewportWidth <= CCConstants.VIEWPORT_TABLET_UPPER_WIDTH) {
if (self.viewportMode() != CCConstants.TABLET_VIEW) {
self.viewportMode(CCConstants.TABLET_VIEW);
}
} else if (self.viewportMode() != CCConstants.PHONE_VIEW) {
self.viewportMode(CCConstants.PHONE_VIEW);
}
};
/**
* Set the number of items per row for responsive viewports
* (tablet and phone).
* @private
*/
this.handleResponsiveViewports = function() {
if (self.viewportMode() == CCConstants.TABLET_VIEW) {
self.itemsPerRow(self.itemsPerRowInTabletView);
self.fetchBlock(0);
self.scrollToTop = false;
$(window).on('scroll', scrollHandler);
}
if (self.viewportMode() == CCConstants.PHONE_VIEW) {
self.itemsPerRow(self.itemsPerRowInPhoneView);
self.scrollToTop = false;
$(window).on('scroll', scrollHandler);
}
};
/**
* Adds and removes scroll event handler from window, based on what
* viewport mode we're in.
* @private
* @param {integer} value The viewport mode.
*/
var handleViewportChange = function(value) {
if (value == self._internalViewportMode()) return;
self._internalViewportMode(value);
if (self.viewportMode() == CCConstants.DESKTOP_VIEW) {
self.itemsPerRow(self.itemsPerRowInDesktopView);
self.clearOnLoad = true;
self.targetPage = 1;
self.fetchBlock(0);
self.scrollToTop = true;
$(window).off('scroll', scrollHandler);
} else if (self.viewportMode() == CCConstants.LARGE_DESKTOP_VIEW) {
self.itemsPerRow(self.itemsPerRowInLargeDesktopView);
self.clearOnLoad = true;
self.targetPage = 1;
self.fetchBlock(0);
self.scrollToTop = true;
$(window).off('scroll', scrollHandler);
}
self.handleResponsiveViewports();
};
this.viewportMode.subscribe(handleViewportChange);
this.checkResponsiveFeatures($(window)[0].innerWidth || $(window).width());
this.handleResponsiveViewports();
this._internalViewportMode(this.viewportMode());
$(window).resize(function() {
// Changing from $(window).width() to $(window)[0].innerWidth for it to work correctly with the
// actual screen width
self.checkResponsiveFeatures($(window)[0].innerWidth || $(window).width());
});
}
var Temp = function(){};
Temp.prototype = Paginated.prototype;
OrderHistoryViewModel.prototype = new Temp();
// setup the inheritance chain
OrderHistoryViewModel.prototype.constructor = OrderHistoryViewModel;
OrderHistoryViewModel.prototype.itemsPerRow = ko.observable(1);
OrderHistoryViewModel.prototype.itemsPerRowInTabletView = 1;
OrderHistoryViewModel.prototype.itemsPerRowInPhoneView = 1;
OrderHistoryViewModel.prototype.itemsPerRowInDesktopView = 1;
OrderHistoryViewModel.prototype.itemsPerRowInLargeDesktopView = 1;
OrderHistoryViewModel.prototype._internalViewportMode = ko.observable(4);
OrderHistoryViewModel.prototype.viewportMode = ko.observable(4);
/**
* Load orders starting from the specified starting index.
* @function OrderHistoryViewModel#fetchBlock
* @param {integer} startingIndex the index of the first record to load.
*/
OrderHistoryViewModel.prototype.fetchBlock = function(startingIndex) {
var url, inputData;
if(this.clearOnLoad) {
this.clearData();
}
inputData = {};
inputData[CCConstants.OFFSET] = startingIndex;
inputData[CCConstants.LIMIT] = this.blockSize * 2;
url = CCConstants.ENDPOINT_GET_ALL_ORDERS_FOR_PROFILE;
spinner.create(this.orderHistoryLoadingOptions);
ccRestClient.request(url, inputData, this.successFunc.bind(this), this.errorFunc.bind(this));
};
/**
* 'Get orders' success callback function.
* Adds the order data to the view model.
* @private
* @function OrderHistoryViewModel#successFunc
* @param {Object} result The orders result object.
*/
OrderHistoryViewModel.prototype.successFunc = function(result) {
if (result && result.items) {
this.addData(result.items, result.total < 0 ? 0 : result.total, result.offset);
}
this.removeSpinner();
};
/**
* 'Get orders' error callback function.
* Publishes the ORDERS_GET_HISTORY_FAILED event.
* @private
* @function OrderHistoryViewModel#errorFunc
* @param {Object} result The error object.
*/
OrderHistoryViewModel.prototype.errorFunc = function(result) {
$.Topic(pubsub.topicNames.ORDERS_GET_HISTORY_FAILED).publishWith(result);
this.removeSpinner();
};
return OrderHistoryViewModel;
}
);
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-ccKoErrorWrapper.html">ccKoErrorWrapper</a></li><li><a href="module-ccKoExtensions.html">ccKoExtensions</a></li></ul><h3>Classes</h3><ul><li><a href="Address.html">Address</a></li><li><a href="CartViewModel.html">CartViewModel</a></li><li><a href="DynamicProperty.html">DynamicProperty</a></li><li><a href="EventDispatcher.html">EventDispatcher</a></li><li><a href="GiftCardViewModel.html">GiftCardViewModel</a></li><li><a href="GiftProductListingViewModel.html">GiftProductListingViewModel</a></li><li><a href="ko.bindingHandlers.background.html">background</a></li><li><a href="ko.bindingHandlers.carouselSwipe.html">carouselSwipe</a></li><li><a href="ko.bindingHandlers.ccForm.html">ccForm</a></li><li><a href="ko.bindingHandlers.ccLink.html">ccLink</a></li><li><a href="ko.bindingHandlers.ccValidation.html">ccValidation</a></li><li><a href="ko.bindingHandlers.checkbox.html">checkbox</a></li><li><a href="ko.bindingHandlers.chosen.html">chosen</a></li><li><a href="ko.bindingHandlers.contextResourcesNamespace.html">contextResourcesNamespace</a></li><li><a href="ko.bindingHandlers.currency.html">currency</a></li><li><a href="ko.bindingHandlers.datepicker.html">datepicker</a></li><li><a href="ko.bindingHandlers.datepopover.html">datepopover</a></li><li><a href="ko.bindingHandlers.draggable.html">draggable</a></li><li><a href="ko.bindingHandlers.droppable.html">droppable</a></li><li><a href="ko.bindingHandlers.fade.html">fade</a></li><li><a href="ko.bindingHandlers.hover.html">hover</a></li><li><a href="ko.bindingHandlers.imageSource.html">imageSource</a></li><li><a href="ko.bindingHandlers.imageZoom.html">imageZoom</a></li><li><a href="ko.bindingHandlers.localeText.html">localeText</a></li><li><a href="ko.bindingHandlers.makeAccess.html">makeAccess</a></li><li><a href="ko.bindingHandlers.modal.html">modal</a></li><li><a href="ko.bindingHandlers.modalTabbingContraint.html">modalTabbingContraint</a></li><li><a href="ko.bindingHandlers.onRender.html">onRender</a></li><li><a href="ko.bindingHandlers.popeditor.html">popeditor</a></li><li><a href="ko.bindingHandlers.popover.html">popover</a></li><li><a href="ko.bindingHandlers.productImageSource.html">productImageSource</a></li><li><a href="ko.bindingHandlers.propertyEditor.html">propertyEditor</a></li><li><a href="ko.bindingHandlers.radio.html">radio</a></li><li><a href="ko.bindingHandlers.richTextEditor.html">richTextEditor</a></li><li><a href="ko.bindingHandlers.scrollAffix.html">scrollAffix</a></li><li><a href="ko.bindingHandlers.select2.html">select2</a></li><li><a href="ko.bindingHandlers.select2Tags.html">select2Tags</a></li><li><a href="ko.bindingHandlers.selectable.html">selectable</a></li><li><a href="ko.bindingHandlers.slickList.html">slickList</a></li><li><a href="ko.bindingHandlers.slide.html">slide</a></li><li><a href="ko.bindingHandlers.slider.html">slider</a></li><li><a href="ko.bindingHandlers.spectrum.html">spectrum</a></li><li><a href="ko.bindingHandlers.tagsInput.html">tagsInput</a></li><li><a href="ko.bindingHandlers.textCheck.html">textCheck</a></li><li><a href="ko.bindingHandlers.timepicker.html">timepicker</a></li><li><a href="ko.bindingHandlers.triggerMessage.html">triggerMessage</a></li><li><a href="ko.bindingHandlers.validatableTarget.html">validatableTarget</a></li><li><a href="ko.bindingHandlers.validatableValue.html">validatableValue</a></li><li><a href="ko.bindingHandlers.widgetLocaleText.html">widgetLocaleText</a></li><li><a href="koValidation.alphaNumeric.html">alphaNumeric</a></li><li><a href="koValidation.alphaNumericNoSpaces.html">alphaNumericNoSpaces</a></li><li><a href="koValidation.alphaNumericNoSpacesWithSeperators.html">alphaNumericNoSpacesWithSeperators</a></li><li><a href="koValidation.alphaNumericWithSeperators.html">alphaNumericWithSeperators</a></li><li><a href="koValidation.bool.html">bool</a></li><li><a href="koValidation.creditcard.html">creditcard</a></li><li><a href="koValidation.cvv.html">cvv</a></li><li><a href="koValidation.endmonth.html">endmonth</a></li><li><a href="koValidation.endyear.html">endyear</a></li><li><a href="koValidation.importFileName.html">importFileName</a></li><li><a href="koValidation.laterDate.html">laterDate</a></li><li><a href="koValidation.match.html">match</a></li><li><a href="koValidation.mediaZipFileName.html">mediaZipFileName</a></li><li><a href="koValidation.number.html">number</a></li><li><a href="koValidation.observablePattern.html">observablePattern</a></li><li><a href="koValidation.password.html">password</a></li><li><a href="koValidation.price.html">price</a></li><li><a href="koValidation.propertyIdAlreadyInUse.html">propertyIdAlreadyInUse</a></li><li><a href="koValidation.propertyNameAlreadyInUse.html">propertyNameAlreadyInUse</a></li><li><a href="koValidation.restrictSlashCharacters.html">restrictSlashCharacters</a></li><li><a href="koValidation.startmonth.html">startmonth</a></li><li><a href="koValidation.startyear.html">startyear</a></li><li><a href="koValidation.uniqueTrimmed.html">uniqueTrimmed</a></li><li><a href="koValidation.uniqueTrimmedCaseInsensitive.html">uniqueTrimmedCaseInsensitive</a></li><li><a href="koValidation.url.html">url</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.addTemplate.html">addTemplate</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.ccDate.html">ccDate</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.ccDateTime.html">ccDateTime</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.ccNumber.html">ccNumber</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.disabled.html">disabled</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.element.html">element</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.embeddedAssistance.html">embeddedAssistance</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.inTabFlow.html">inTabFlow</a></li><li><a href="module-ccKoExtensions-ko.bindingHandlers.setContextVariable.html">setContextVariable</a></li><li><a href="NavStateViewModel.html">NavStateViewModel</a></li><li><a href="OrderHistoryViewModel.html">OrderHistoryViewModel</a></li><li><a href="OrderViewModel.html">OrderViewModel</a></li><li><a href="ParentOrganisation.html">ParentOrganisation</a></li><li><a href="ProductListingSearchViewModel.html">ProductListingSearchViewModel</a></li><li><a href="ProductListingViewModel.html">ProductListingViewModel</a></li><li><a href="ProductViewModel.html">ProductViewModel</a></li><li><a href="PubSub.topicNames.html">topicNames</a></li><li><a href="resetCVV.html">resetCVV</a></li><li><a href="resetPaymentDetails.html">resetPaymentDetails</a></li><li><a href="SearchRestClient.html">SearchRestClient</a></li><li><a href="UserViewModel.html">UserViewModel</a></li><li><a href="WidgetViewModel.html">WidgetViewModel</a></li><li><a href="WishlistContentViewModel.html">WishlistContentViewModel</a></li></ul><h3>Namespaces</h3><ul><li><a href="ko.bindingHandlers.html">bindingHandlers</a></li><li><a href="ko.extenders.html">extenders</a></li><li><a href="koValidation.html">koValidation</a></li></ul><h3>Global</h3><ul><li><a href="global.html#CCEETagProcessor">CCEETagProcessor</a></li><li><a href="global.html#isValidDeterminewhetherornotthepaymentdetailsobjectisvalidbasedonthevalidityofitscomponentparts.Thiswillnotcauseerrormessagestobedisplayedforanyobservablevaluesthatareunchangedandhaveneverreceivedfocusontherelatedformfield(s).">isValid
Determine whether or not the payment details object is valid
based on the validity of its component parts. This will not
cause error messages to be displayed for any observable values
that are unchanged and have never received focus on the
related form field(s).</a></li><li><a href="global.html#validatePaymentDetailsForceallrelevantmemberobservablestoperformtheirvalidationnow&displaytheerrors(ifany)">validatePaymentDetails
Force all relevant member observables to perform their
validation now & display the errors (if any)</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0</a> on Mon Oct 10 2016 10:49:04 GMT+0100 (BST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>