PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/MS Silk/Scripts/Debug/mstats.imminent-reminders.js

#
JavaScript | 115 lines | 68 code | 17 blank | 30 comment | 3 complexity | a2f4ff17d5c10a8eca65a8aa22ac8772 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Silk : Web Client Guidance
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. /*jslint onevar: true, undef: true, newcap: true, regexp: true, plusplus: true, bitwise: true, devel: true, maxerr: 50 */
  18. /*global jQuery */
  19. (function (mstats, $) {
  20. $.widget('mstats.imminentRemindersPane', {
  21. options: {
  22. // Default to $.ajax when sendRequest is undefined.
  23. // The extra function indirection allows $.ajax substitution because
  24. // the widget framework is using the real $.ajax during options initialization.
  25. sendRequest: function (ajaxOptions) { $.ajax(ajaxOptions); },
  26. // invalidateData allows the imminentReminders to invalidate data
  27. // stored in the data cache.
  28. invalidateData: function () { mstats.log('The invalidateData option on imminentReminders has not been set'); },
  29. // option providing the event publisher used for communicating with the status widget.
  30. publish: function() { mstats.log('The publish option on imminentReminders has not been set'); }
  31. },
  32. _create: function () {
  33. this._getImminentReminderData();
  34. },
  35. _applyTemplate: function (data) {
  36. if (!$(this.options.templateId).length) {
  37. mstats.log('Cannot apply templates as there is no template defined.');
  38. return;
  39. }
  40. // Wrapped to make it easier to template with header data.
  41. var wrappedData = { ReminderList: data };
  42. this.element.find('#summary-reminders-content')
  43. .html($(this.options.templateId).tmpl(wrappedData, {
  44. createRemindersLink: function (vehicleId) {
  45. var state = $.bbq.getState() || {},
  46. newUrlBase = mstats.getBaseUrl();
  47. state.layout = 'reminders';
  48. state.vid = vehicleId;
  49. return $.param.fragment(newUrlBase, state);
  50. }
  51. }));
  52. },
  53. _getImminentReminderData: function () {
  54. var that = this;
  55. this._hideReminders();
  56. this.options.sendRequest({
  57. url: this.options.dataUrl,
  58. success: function (data) {
  59. that._applyTemplate(data);
  60. that._showReminders();
  61. // ensure that setOption is called with the provided options
  62. that.option(that.options);
  63. },
  64. error: function () {
  65. that._hideReminders();
  66. that._showErrorMessage();
  67. }
  68. });
  69. },
  70. _showReminders: function () {
  71. this.element.find('#summary-reminders-content').show();
  72. },
  73. _hideReminders: function () {
  74. this.element.find('#summary-reminders-content').hide();
  75. },
  76. refreshData: function () {
  77. this._getImminentReminderData();
  78. },
  79. requeryData: function () {
  80. this.options.invalidateData(this.options.dataUrl);
  81. this.refreshData();
  82. },
  83. /********************************************************
  84. * Status Methods
  85. ********************************************************/
  86. _publishStatus: function (status) {
  87. this.options.publish(mstats.events.status, status);
  88. },
  89. // hide the vehicles list and show the status widget in the error state
  90. _showErrorMessage: function () {
  91. this._publishStatus({
  92. type: 'loadError',
  93. message: 'An error occurred while loading the summary reminders data. Please try again.',
  94. duration: 10000
  95. });
  96. }
  97. });
  98. }(this.mstats, jQuery));