1/** 2 * @classdesc 3 * The button used to send 'set user home page' requests 4 * 5 * @require 'jQuery' 6 * @require 'message.Flash' 7 * 8 * @constructor 9 * @param {object} obj_options SetHomeButton options. Possible keys are: 10 * - $button {Element} The button element 11 * - url {string} Url to use when sending a 'set home' request 12 * - userid {string} User id (i.e. username) 13 */ 14var SetHomeButton = function(opt_options) { 15 var options = opt_options || {}; 16 this.initialize_(options); 17}; 18 19 20/** 21 * @param {object} SetHomeButton options 22 * @private 23 */ 24SetHomeButton.prototype.initialize_ = function(options) { 25 26 /** 27 * @define {Element} The button element 28 */ 29 this.$button_ = options.$button; 30 31 /** 32 * @define {string} User id (i.e. username) 33 */ 34 this.userid_ = options.userid; 35 36 /** 37 * @define {string} Url to use when sending a 'set home' request 38 */ 39 this.url_ = options.url; 40 41 // event listeners 42 this.$button_.click($.proxy(this.handleButtonClick_, this)); 43}; 44 45 46/** 47 * Callback method called when button is clicked. 48 * @param {Event} event 49 * @private 50 */ 51SetHomeButton.prototype.handleButtonClick_ = function(event) { 52 event.preventDefault(); 53 54 if (this.userid_ === null) { 55 return; 56 } 57 58 var location = window.location; 59 var path = [location.pathname, location.search, location.hash].join(''); 60 $.ajax({ 61 type: 'POST', 62 data: {path: path}, 63 url: this.url_, 64 success: $.proxy(this.handleSetSuccess_, this), 65 error: $.proxy(this.handleSetError_, this) 66 }); 67}; 68 69 70/** 71 * Callback method called when a 'set' request is successfully completed 72 * @param {Event} event 73 * @private 74 */ 75SetHomeButton.prototype.handleSetSuccess_ = function(response) { 76 if (response.status == 0) { 77 this.handleSetError_(response); 78 return; 79 } 80 81 new mg.message.Flash('success', i18n.gettext('Home page successfully saved.')); 82}; 83 84 85/** 86 * Callback method called when a 'set' request is failed to complete 87 * @param {Event} event 88 * @private 89 */ 90SetHomeButton.prototype.handleSetError_ = function(response) { 91 var msg = []; 92 93 msg.push(i18n.gettext('Error, home page could not be saved.')) 94 if (response && response.errors && response.errors.length) { 95 msg.push(i18n.gettext('The server replied: "')); 96 msg.push(errors.join(', ')); 97 msg.push('".'); 98 } 99 100 new mg.message.Flash('danger', msg.join('')); 101};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.