1var turprofi = turprofi || {}; 2 3turprofi.subscribe = function subscribe (element, url, routes) { 4 var self = this; 5 6 this.$element = $(element); 7 8 this.eventId = this.get("event-id"); 9 this.url = url; 10 this.routes = routes; 11 12 this.$popup = $("#iGoConfirmation"); 13 this.$participants = $("#participants-" + this.eventId); 14 15 $(document).on("click", "a", function (e) { 16 var $that = $(this); 17 18 if ($that.hasClass("i-cancel")) { 19 self.$popup.modal("hide"); 20 21 return false; 22 } 23 else if ($that.hasClass("i-confirm-revoke") && $that.attr("data-event-id") == self.eventId) { 24 self.request(false); 25 26 self.onSubscriptionRevoked(); 27 28 self.$popup.modal("hide"); 29 30 e.stopImmediatePropagation(); 31 32 return false; 33 } 34 35 return true; 36 }); 37}; 38 39/** 40 * Get element with key form element data object 41 * 42 * @param key 43 * @return {*} 44 */ 45turprofi.subscribe.prototype.get = function (key) { 46 return this.$element.data(key); 47}; 48 49/** 50 * Return current state, true for 'On', false for 'Off' 51 * 52 * @return {*} 53 */ 54turprofi.subscribe.prototype.getState = function () { 55 return +this.$element.attr('data-subscribed') || 0; 56}; 57 58turprofi.subscribe.prototype.onSuccessfulSubscription = function () { 59 this.$element.removeClass('btn-primary green') 60 .addClass('btn--grey') 61 .attr('data-subscribed', 1) 62 .removeAttr('disabled') 63 .html(this.get("off") + ' <span class="cross"> </span>'); 64 65 if (this.$participants.length) { 66 this.$participants.html(parseInt(this.$participants.html()) + 1); 67 } 68 else { 69 this.$element.closest('.do-i-go').append( 70 '<div class="num-to-go">ÐдÑÑ <span id="participants-' + this.eventId + '">1</span> Ñел-ка</div>' 71 ); 72 this.$participants = $('#participants-' + this.eventId); 73 } 74 $('#webinar-view-' + this.eventId).show(); 75 76 $(document).trigger("iGo", [1]); 77 78 this.displaySuccessfulSubscriptionDialog(); 79}; 80 81turprofi.subscribe.prototype.displayConfirmRevokeDialog = function () { 82 this.displayDialog(this.routes.confirmSubscriptionRevoke, {id: this.eventId}); 83}; 84 85turprofi.subscribe.prototype.displaySuccessfulSubscriptionDialog = function () { 86 this.displayDialog(this.routes.successfulSubscription, {id: this.eventId}); 87}; 88 89 90turprofi.subscribe.prototype.onSubscriptionRevoked = function () { 91 var amount = parseInt(this.$participants.html()) - 1; 92 93 if (amount < 0) { 94 amount = 0; 95 } 96 97 this.$element.removeClass('btn-success btn--grey blue') 98 // .addClass('btn-primary green') 99 .attr('data-subscribed', 0) 100 .removeAttr('disabled') 101 .html(this.get("on")); 102 103 this.$participants.html(amount); 104 $('#webinar-view-' + this.eventId).hide(); 105 106 $(document).trigger("iGo", [-1]); 107}; 108 109turprofi.subscribe.prototype.request = function (raiseCallbacks) { 110 var self = this; 111 112 if (!self.validate()) { 113 return; 114 } 115 116 if ("undefined" == typeof raiseCallbacks) { 117 raiseCallbacks = true; 118 } 119 120 $.post(Routing.generate(this.url, {id: this.eventId, type: 'webinar', silent: 0}), {}, "json") 121 .success(function (data) { 122 123 if (raiseCallbacks) { 124 self.getState() ? self.onSubscriptionRevoked() : self.onSuccessfulSubscription(); 125 } 126 127 }); 128}; 129 130turprofi.subscribe.prototype.validate = function () { 131 if ("undefined" == typeof currentUserId) { 132 return true; 133 } 134 135 var self = this, 136 uri, temp, 137 modalWnd = $('#validationWindow'), 138 fillProfileLink = modalWnd.find("[data-role=redirect]"); 139 140 var url = Routing.generate('validate_user_webinar_registration'); 141 var validation = false; 142 $.ajax({ 143 url: url, 144 async: false, 145 success: function (data) { 146 if (data.validation) { 147 validation = true; 148 } 149 else { 150 temp = fillProfileLink.data("canonical-path") + "?event=" + self.eventId; 151 fillProfileLink.attr("href", temp); 152 153 modalWnd.modal('show'); 154 } 155 156 return validation; 157 } 158 }); 159 160 return validation; 161}; 162 163turprofi.subscribe.prototype.displayDialog = function (uri, args) { 164 var self = this; 165 166 $.get(Routing.generate(uri, args)) 167 .success(function (html) { 168 self.$popup.html(html).modal("show"); 169 }); 170}; 171 172function iGoButton(path) { 173 $("button.i-go, a.i-go").on("click touchstart", function (e) { 174 // TODO: Get rid of the global var 'routes' 175 var subscribe = new turprofi.subscribe(this, path, uris); 176 177 178 var off = $(this).data('off'); 179 var on = $(this).data('on'); 180 var event_id = $(this).data('event-id'); 181 var _this = $("[data-event-id=" + event_id + "]"); 182 var participants = $('#participants-' + event_id); 183 184 if ("undefined" == typeof event_id) { 185 return; 186 } 187 // Hello world! 188 e.stopImmediatePropagation(); 189 190 _this.attr('disabled', true); 191 192 console.log(subscribe.getState()); 193 194 if (subscribe.getState()) { 195 // Revoke subscription 196 subscribe.displayConfirmRevokeDialog(); 197 } 198 else { 199 // Subscribe 200 subscribe.request(); 201 } 202 203 return false;
204 }); 205}
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.