1jQuery.widget( 'gc.talksWidget', { 2 conversationsData: {}, 3 talksWindowShowed: false, 4 5 options: { 6 fullMode: false, 7 openedConversationId: false, 8 allowGuest : false 9 }, 10 _create: function() { 11 12 var self = this; 13 this.defaultRespondent = null; 14 this.element.addClass('activated-talks-widget'); 15 16 this.talksWidgetButton = this.createButton(); 17 18 this.talksWidgetButton.click( function() { 19 self.talksWidgetButton.popover('hide'); 20 self.showTalksWindow(true); 21 }); 22 23 this.subscribeConversations(); 24 25 if (!this.options.openedConversationId) { 26 var openedConversationId = window.gcGetCookie("savedConversationId"); 27 if (openedConversationId > 0 && !this.isMobileVersion()) { 28 this.options.openedConversationId = openedConversationId; 29 } 30 31 var cid = getParamFromLocation("openedConversationId"); 32 if (cid) { 33 this.options.openedConversationId = cid; 34 } 35 } 36 37 if ( this.options.openedConversationId ) { 38 self.showTalksWindow(); 39 } 40 41 if (this.options.allowGuest) { 42 self.loadCounter(); 43 } 44 }, 45 createButton: function() { 46 if (window.isGetplatinum) { 47 $btn = $(`<div class="talks-widget-button" style=" 48 background-image: url('/public/img/talks_widget/getplatinum-dialog.svg'); 49 background-color: #067AFF; 50 "></div>`); 51 } else { 52 $btn = $(`<div class="talks-widget-button"></div>`) 53 } 54 $btn.appendTo( document.body ) 55 56 $counter = $('<div class="conversations-counter"></div>') 57 $counter.appendTo( $btn ) 58 $counter.hide(); 59 60 return $btn; 61 }, 62 createTalksWindow: function() { 63 var self = this; 64 if ( this.talksWindow ) { 65 return; 66 } 67 68 $( window ).resize( function() { 69 self.adoptSize(); 70 }) 71 72 $window = $('<div class="talks-widget-window"></div>') 73 $window.hide(); 74 $window.appendTo( document.body ) 75 this.talksWindow = $window; 76 77 if ( this.isFullMode() ) { 78 this.talksWindow.addClass('full-screen-mode') 79 } 80 this.toggleMainMenuAdopt(); 81 82 $header = $('<div class="talks-widget-header"></div>') 83 $header.appendTo( $window ) 84 this.headerEl = $header 85 var closeContainerSelector = window.isAccountRedesignEnabled 86 ? '<i class="btn-close gc-icons gc-close"></i>' 87 : '<span class="btn-close fa fa-times"></span>'; 88 this.btnClose = $(closeContainerSelector); 89 this.btnClose.appendTo( this.headerEl ) 90 91 this.backBtn = $backBtn = $('<span class="btn-back fa fa-bars"></span>') 92 $backBtn.appendTo( this.headerEl ) 93 this.backBtn.hide(); 94 95 this.backBtn.click( function() { 96 self.showConversationList(); 97 window.gcSetCookie( "savedConversationId", 0, {path : '/'} ); 98 }) 99 100 this.btnClose.click( function() { 101 self.closeTalksWindow(); 102 window.gcSetCookie( "savedConversationId", 0, {path : '/'} ); 103 }) 104 105 this.captionEl = $('<div class="caption"></div>' ) 106 this.captionEl.appendTo ( this.headerEl ) 107 108 109 this.bodyBlock = $('<div class="talks-widget-body"></div>') 110 this.bodyBlock.appendTo( $window ) 111 112 this.conversationsListBlock = $('<div class="conversations-list-block"></div>') 113 this.conversationsListBlock.appendTo( this.bodyBlock ) 114 115 this.conversationsList = $('<div class="conversations-list"></div>') 116 this.conversationsList.appendTo( this.conversationsListBlock ) 117 118 this.conversationListFooter = $('<div class="conversation-list-footer"></div>') 119 this.conversationListFooter.appendTo( this.conversationsListBlock ) 120 121 this.newConversationBtn = $('<button class="btn btn-new btn-primary"><span class="fa fa-pencil"></span> ' + Yii.t("widgets", "New conversation") + ' </button>') 122 123 if ( this.options.fullMode ) { 124 this.newConversationBtn.appendTo( this.headerEl ) 125 } 126 else { 127 this.newConversationBtn.appendTo( this.conversationListFooter ) 128 } 129 130 131 this.newConversationBtn.click( function() { 132 133 if ( window.userInfo && window.userInfo.isTeacher ) { 134 alert(Yii.t("widgets", "The administrator of the account and the employee cannot write an appeal to the technical support of the account") 135 + ". " + Yii.t("widgets", "If you want to contact technical support")); 136 return; 137 } 138 139 self.showNewConversationBlock(); 140 }); 141 142 143 144 this.selectedConversationBlock = $('<div class="selected-conversation"></div>') 145 this.selectedConversationBlock.appendTo( this.bodyBlock ) 146 this.selectedConversationBlock.hide(); 147 148 this.newConversationBlock = $('<div class="new-conversation"></div>') 149 this.newConversationBlock.appendTo( this.bodyBlock ) 150 this.newConversationBlock.hide(); 151 152 this.respondentList = $('<div class="respondent-list"></div>')
153 this.respondentList.appendTo( this.newConversationBlock ) 154 155 156 this.talksWindow = $window; 157 this.adoptSize(); 158 }, 159 createHelpdeskMinichatWindow: function() { 160 var self = this; 161 if ( this.talksWindow ) { 162 return; 163 } 164 165 $( window ).resize( function() { 166 self.adoptSize(); 167 }) 168 const iframeUrl = `/pl/helpdesk/helpdesk?type=compact_chat&userId=${window.accountUserId}&isIframe=1`; 169 const iframeContent = `<iframe src="${iframeUrl}" width="100%" height="100%" style="border:none"></iframe>`; 170 $window = $(`<div class="talks-widget-window">${iframeContent}</div>`) 171 $window.appendTo( document.body ) 172 this.talksWindow = $window; 173 }, 174 showTalksWindow: function(click) { 175 if (click && window.helpdeskTalksEnabledFeature) { 176 if (this.talksWindow ) { 177 this.talksWindow.show(); 178 } else { 179 this.createHelpdeskMinichatWindow(); 180 } 181 return; 182 } 183 184 if (! this.talksWindow ) { 185 this.createTalksWindow(); 186 } 187 188 var self = this; 189 190 setTimeout( function() { 191 self.talksWindowShowed = true; 192 self.talksWindow.show(); 193 self.loadConversations(); 194 195 self.loadRespondents(); 196 197 self.showConversationList(); 198 199 self.adoptSize(); 200 }, 10 ); 201 202 }, 203 204 closeTalksWindow: function() { 205 this.talksWindowShowed = false; 206 this.talksWindow.hide(); 207 }, 208 209 setTitle: function( title, titleLink ) { 210 if ( titleLink ) { 211 title = "<a href='" + titleLink + "'>" + title +"</a>" 212 } 213 this.captionEl.html( title ); 214 }, 215 216 loadCounter: function() { 217 var self = this; 218 ajaxCall("/cms/counters/conversationData", {}, {}, function (response) { 219 self.setCounter(response.counters.conversationsData); 220 }); 221 }, 222 223 loadConversations: function(offset) { 224 225 var self = this; 226 227 if ( ! self.conversationsList ) { 228 return; 229 } 230 231 if ( offset === undefined ) { 232 offset = 0; 233 } 234 235 var linkMoveToTopFunction = function( $block ) { 236 $block.on('comment:added', function() { 237 $block.prependTo( self.conversationsList ) 238 }) 239 } 240 241 ajaxCall( "/pl/talks/conversation/model-list", {offset: offset}, {}, function( response ) { 242 if(!offset) { 243 self.conversationsList.empty(); 244 } 245 246 for( key in response.data.models ) { 247 var model = response.data.models[key]; 248 249 var $convBlock = $( 250 '<div class="conversation-annotate">' + 251 '<div class="conversation-img-block"><div class="conversation-img"></div></div>' + 252 '<div class="conversation-data-block">' + 253 '<div class="conversation-title-block">' + 254 '<span class="conversation-title"></span>' + 255 '<div class="conversation-time"></div>' + 256 '<div class="conversation-fresh-comment-count" style="bottom: 16px;"></div>' + 257 '<div class="conversation-text"></div>' + 258// '<div class="conversation-object-title"></div>' + 259 (window.userInfo.isHumanDesign == "1" 260 ? '<div class="glyphicon glyphicon-trash delete-conversation pull-right" style="cursor: pointer; color: #999;margin-right: 30px;" data-conv-id="' + 261 model.id + '" title="'+ Yii.t("widgets", "Delete conversation") +'"></div>' 262 : ' ' 263 ) + 264 '</div>' + 265 '</div>' + 266 '</div>' 267 ); 268 $convBlock.addClass('conversation-' + model.id ) 269 270 $convBlock.appendTo(self.conversationsList); 271 $convBlock.data( 'conv-id', model.id ) 272 $convBlock.data( 'conv-title', model.title ) 273 $convBlock.data( 'conv-title-link', model.title_link ) 274 275 $convBlock.find('.delete-conversation').click(function(e) { 276 e.preventDefault(); 277 e.stopPropagation(); 278 var convId = $( this ).data('conv-id'); 279 var result = confirm(Yii.t("widgets", "Do you want to delete the conversation?")); 280 if (result) { 281 ajaxCall( "/pl/talks/conversation/delete?id=" + convId, {}, {}, function( response ) { 282 283 if ( response.data.delete) { 284 $(".conversation-" + convId).remove(); 285 } 286 }); 287 } 288 289 }); 290 291 $convBlock.click( function() { 292 $('.conversation-annotate.active').removeClass( 'active' ) 293 $(this).addClass('active') 294 self.openConversation( $(this).data( 'conv-id' ), $(this).data( 'conv-title' ), $(this).data( 'conv-title-link' ) ) 295 }); 296 297 $convBlock.conversationAnnotate({conversation: model }); 298 299 linkMoveToTopFunction( $convBlock ) 300 } 301 302 if ( response.data.leftCount > 0 && window.userInfo.isHumanDesign == "1") {
303 $nextEl = $('<div style="background: #F0F0F0; cursor:pointer; text-align: center; padding: 5px"> '+ Yii.t("widgets", "More") +' </div>') 304 $nextEl.appendTo( self.conversationsList ) 305 $nextEl.click( function() { 306 // alert(response.data.nextOffset); 307 self.loadConversations( response.data.nextOffset ); 308 $(this).detach(); 309 }) 310 } 311 312 if ( self.options.openedConversationId ) { 313 self.conversationsList.find( ".conversation-" + self.options.openedConversationId ).click(); 314 self.options.openedConversationId = null; 315 } 316 317 //self.conversationsBlock.html( "" ); 318 319 } ) 320 321 }, 322 323 loadRespondents: function() { 324 325 var self = this; 326 327 ajaxCall( "/pl/talks/respondent/model-list", {}, {}, function( response ) { 328 self.respondentList.empty(); 329 330 for( key in response.data.models ) { 331 var model = response.data.models[key] 332 333 if ( ! self.defaultRespondent ) { 334 self.defaultRespondent = model.id; 335 } 336 337 var $block = $( '<div class="respondent-annotate"></div>' ) 338 339 if ( model.icon_url ) { 340 var $imgBlock = $('<div class="respondent-img-block"></div>') 341 $imgBlock.html('<img src="' + model.icon_url + '">') 342 $imgBlock.appendTo($block) 343 } 344 345 var $dataBlock = $( '<div class="respondent-data-block"></div>') 346 $dataBlock.appendTo( $block ) 347 348 var $titleBlock = $( '<div class="respondent-title-block"></div>') 349 $titleBlock.appendTo( $dataBlock ) 350 351 var $titleEl = $( '<span class="respondent-title"></span>' ) 352 $titleEl.html( model.label ) 353 $titleEl.appendTo( $titleBlock ) 354 355 var $timeEl = $( '<div class="respondent-time"></div>') 356 $timeEl.html( model.time_str ) 357 $timeEl.appendTo( $titleBlock ) 358 359 var $textBlock = $( '<div class="respondent-text-block"></div>') 360 $textBlock.html( model.text ) 361 $textBlock.appendTo( $dataBlock ) 362 363 $block.appendTo(self.respondentList); 364 $block.data( 'respondent-id', model.id ); 365 366 $block.click( function() { 367 self.selectRespondent( $(this).data( 'respondent-id' ) ) 368 }) 369 370 } 371 372 //self.conversationsBlock.html( "" ); 373 374 } ) 375 376 }, 377 378 showNewConversationBlock: function() { 379 380 if ( ! this.isFullMode() ) { 381 this.conversationsListBlock.hide(); 382 } 383 this.selectedConversationBlock.hide(); 384 this.newConversationBlock.show(); 385 386 this.setTitle(Yii.t("widgets", "New conversation")); 387 388 if ( this.respondentList.find( '.respondent-annotate' ).length == 1 ) { 389 this.respondentList.find( '.respondent-annotate' ).click(); 390 } 391 392 this.backBtn.show(); 393 if ( ! this.isFullMode() ) { 394 this.newConversationBtn.hide(); 395 } 396 }, 397 398 openConversationBlock: function( conversationParams, title, titleLink ) { 399 if ( this.currentConversationBlock ) { 400 this.currentConversationBlock.remove(); 401 } 402 403 this.currentConversationBlock = $('<div></div>') 404 this.currentConversationBlock.css('height', '100%'); 405 this.currentConversationBlock.appendTo( this.selectedConversationBlock ); 406 407 if ( title ) { 408 this.setTitle( title, titleLink ) 409 } 410 411 412 this.currentConversationBlock.conversationWidget({ conversationParams: conversationParams }); 413 414 415 this.selectedConversationBlock.show(); 416 417 if ( ! this.isFullMode() ) { 418 this.conversationsListBlock.hide(); 419 } 420 this.newConversationBlock.hide(); 421 422 this.backBtn.show(); 423 if ( ! this.isFullMode() ) { 424 this.newConversationBtn.hide(); 425 } 426 }, 427 428 openConversation: function( id, title, titleLink ) { 429 window.gcSetCookie( "savedConversationId", id, {path : '/'} ); 430 this.openConversationBlock({id: id}, title, titleLink) 431 432 }, 433 434 selectRespondent: function( id ) { 435 this.setTitle(Yii.t("widgets", "New conversation")); 436 this.openConversationBlock({objectTypeClass: "app\\modules\\talks\\models\\AppealToRespondent", objectId: id}) 437 }, 438 439 showConversationList: function() { 440 441 if ( this.currentConversationBlock ) { 442 this.currentConversationBlock.remove(); 443 } 444 445 this.selectedConversationBlock.hide(); 446 this.conversationsListBlock.show(); 447 this.newConversationBlock.hide(); 448 449 this.backBtn.hide(); 450 this.newConversationBtn.show(); 451 452 453 this.setTitle(Yii.t("widgets", "Communication")); 454 }, 455 456 toggleMainMenuAdopt: function() { 457 if ( $('#gcAccountUserMenu .nav.nav-pills').length ) { 458 this.talksWindow.addClass('gc-menu'); 459 this.talksWindow.removeClass('wide'); 460 this.talksWindow.removeClass('no-menu'); 461 } 462 if ( $('.gc-main-content').hasClass('no-menu') ) { 463 this.talksWindow.removeClass('wide'); 464 this.talksWindow.addClass('no-menu'); 465 } else 466 if ( $('.gc-main-content').hasClass('wide') ) { 467 this.talksWindow.removeClass('no-menu'); 468 this.talksWindow.addClass('wide'); 469 } 470 }, 471 472 adoptSize: function() { 473 474 var headerHeight = this.headerEl.height() + 12; 475 476 var height = this.bodyBlock.parent().height() - headerHeight - $('.main-nav-list').height(); 477 this.bodyBlock.height( height ); 478 479 if ( this.isFullMode() ) { 480 //this.talksWindow.css( "left", "70px" ); 481 this.toggleMainMenuAdopt(); 482 this.talksWindow.css( "width", ($(document.body).width() - this.talksWindow.position().left ) + "px" ); 483 } 484 485 this.conversationsList.height( (this.conversationsListBlock.height() - this.conversationListFooter.height() - 20) + "px" ); 486 487 //this.conversationsBlock.height( 100 ) 488 }, 489 subscribeConversations: function() { 490 var self = this; 491 492 if ( window.accountUserWebSocketConnection && window.conversationsUserChannel ) { 493 var channel = window.conversationsUserChannel; 494 window.accountUserWebSocketConnection.subscribeChannel( channel, 495 function(message, json){ 496 if ( json.action == "member_added" ) { 497 setTimeout( function() { 498 self.loadConversations(); 499 }, 100 ) 500 } 501 if ( json.action == "reset_viewed" ) { 502 delete self.conversationsData[json.conversation_id]; 503 self.showCounterValue(); 504 } 505 if ( json.action == "new_comment" ) { 506 self.talksWidgetButton.popover('destroy'); 507 self.talksWidgetButton.popover({ 508 placement: "top", 509 content: json.comment.text, 510 animation: false, 511 trigger: 'hover' 512 }); 513 514 self.talksWidgetButton.data('bs.popover').options.title = json.comment.user_name; 515 self.talksWidgetButton.data('bs.popover').options.content = json.comment.text; 516 517 self.conversationsData[json.conversation_id] = 1; 518 self.showCounterValue(); 519 520 if ( ! self.talksWindowShowed ) { 521 self.talksWidgetButton.popover('show') 522 } 523 } 524 if ( json.action == "manager_changed" ) { 525 $(document).trigger('gc:manager:changed'); 526 } 527 } 528 ); 529 } 530 }, 531 setCounter: function( conversationsData ) { 532 this.conversationsData = conversationsData; 533 this.showCounterValue() 534 535 }, 536 showCounterValue: function() { 537 var i = 0; 538 for( var key in this.conversationsData ) { 539 i += parseInt(this.conversationsData[key]); 540 } 541 542 var counter = i; 543 544 $('.conversations-counter').html(counter); 545 546 if (counter > 0) { 547 $('.conversations-counter').show(); 548 } else { 549 $('.conversations-counter').hide(); 550 } 551 }, 552 isFullMode() { 553 if ( this.options.fullMode && $(window).width() > 800 ) { 554 return true; 555 } 556 return false;
557 }, 558 isMobileVersion: () => window.matchMedia("(max-width: 768px)").matches, 559 talkWithUser(userId) { 560 561 ajaxCall("/pl/talks/conversation/get-direct-talk?userId=" + userId, {}, {}, function (response) { 562 $('.talks-widget').talksWidget('showTalksWindow'); 563 564 565 if (response.data.found) { 566 setTimeout(function () { 567 $('.talks-widget').talksWidget('openConversation', response.data.id, response.data.info.title, response.data.info.title_link) 568 }, 50) 569 } 570 else { 571 setTimeout(function () { 572 $('.talks-widget').talksWidget('openConversationBlock', { 573 objectTypeClass: "app\\modules\\user\\models\\User", 574 objectId: userId 575 }, response.data.name, response.data.profileLink) 576 }, 50) 577 } 578 }) 579 } 580 581} ); 582 583function closeMiniChatWindow() { 584 $('.talks-widget').talksWidget('closeTalksWindow'); 585}
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.