src/pyams_content/skin/resources/js/pyams_content.js
changeset 35 7cdbe0f6e5c2
parent 26 7f025cebf19d
child 67 aaf228e67189
equal deleted inserted replaced
34:f907592596bf 35:7cdbe0f6e5c2
   331 											plugin.opts.populateResults.call(plugin, plugin.results, data.result,
   331 											plugin.opts.populateResults.call(plugin, plugin.results, data.result,
   332 																			 {term: ''});
   332 																			 {term: ''});
   333 									   });
   333 									   });
   334 				}
   334 				}
   335 			}
   335 			}
       
   336 		},
       
   337 
       
   338 
       
   339 		/**
       
   340 		 * Review comments management
       
   341 		 */
       
   342 		review: {
       
   343 
       
   344 			timer: null,
       
   345 			timer_duration: {
       
   346 				general: 30000,
       
   347 				chat: 5000
       
   348 			},
       
   349 
       
   350 			initComments: function(element) {
       
   351 				var chat = $('.chat-body', element);
       
   352 				chat.animate({scrollTop: chat[0].scrollHeight}, 1000);
       
   353 				clearInterval(PyAMS_content.review.timer);
       
   354 				PyAMS_content.review.timer = setInterval(PyAMS_content.review.updateComments,
       
   355 														 PyAMS_content.review.timer_duration.chat);
       
   356 				MyAMS.skin.registerCleanCallback(PyAMS_content.review.cleanCommentsCallback);
       
   357 			},
       
   358 
       
   359 			cleanCommentsCallback: function() {
       
   360 				clearInterval(PyAMS_content.review.timer);
       
   361 				PyAMS_content.review.timer = setInterval(PyAMS_content.review.updateComments,
       
   362 														 PyAMS_content.review.timer_duration.general);
       
   363 			},
       
   364 
       
   365 			updateComments: function() {
       
   366 				var badge = $('.badge', 'nav a[href="#review-comments.html"]'),
       
   367 					count;
       
   368 				var chat = $('.chat-body', '.widget-body');
       
   369 				if (chat.exists()) {
       
   370 					count = $('.message', chat).length;
       
   371 				} else {
       
   372 					count = parseInt(badge.text());
       
   373 				}
       
   374 				MyAMS.ajax.post('get-last-review-comments.json', {count: count}, function(result) {
       
   375 					if (chat.exists()) {
       
   376 						badge.removeClass('bg-color-danger')
       
   377 							 .addClass('bg-color-info');
       
   378 					}
       
   379 					if (count !== result.count) {
       
   380 						badge.text(result.count).removeClass('hidden');
       
   381 						if (chat.exists()) {
       
   382 							$('.messages', chat).append(result.content);
       
   383 							chat.animate({scrollTop: chat[0].scrollHeight}, 1000);
       
   384 						}
       
   385 						if (!chat.exists()) {
       
   386 							badge.removeClass('bg-color-info')
       
   387 								 .addClass('bg-color-danger')
       
   388 								 .animate({'padding': '3px 12px 2px',
       
   389 										   'margin-right': '9px'}, 'slow', function() {
       
   390 									$(this).animate({'padding': '3px 6px 2px',
       
   391 													 'margin-right': '15px'}, 'slow');
       
   392 								 });
       
   393 						}
       
   394 					}
       
   395 				});
       
   396 			},
       
   397 
       
   398 			initCommentData: function(veto) {
       
   399 				var chat = $('.chat-body', '.widget-body');
       
   400 				return {count: $('.message', chat).length};
       
   401 			},
       
   402 
       
   403 			addCommentCallback: function(options) {
       
   404 				var form = $(this);
       
   405 				var widget = form.parents('.widget-body');
       
   406 				$('.messages', widget).append(options.content);
       
   407 				$('textarea[name="comment"]', form).val('');
       
   408 				var chat = $('.chat-body', widget);
       
   409 				chat.animate({scrollTop: chat[0].scrollHeight}, 1000);
       
   410 				$('.badge', 'nav a[href="#review-comments.html"]').text(options.count).removeClass('hidden');
       
   411 			}
   336 		}
   412 		}
   337 	};
   413 	};
   338 
   414 
   339 	globals.PyAMS_content = PyAMS_content;
   415 	globals.PyAMS_content = PyAMS_content;
   340 
   416 
   350 				PyAMS_content.links.refreshContainer(settings);
   426 				PyAMS_content.links.refreshContainer(settings);
   351 				break;
   427 				break;
   352 			case 'galleries_container':
   428 			case 'galleries_container':
   353 				PyAMS_content.galleries.refreshContainer(settings);
   429 				PyAMS_content.galleries.refreshContainer(settings);
   354 				break;
   430 				break;
       
   431 			case 'review_comments':
       
   432 				PyAMS_content.review.updateComments();
       
   433 				break;
   355 		}
   434 		}
   356 	});
   435 	});
   357 
   436 
       
   437 	var badge = $('.badge', 'nav a[href="#review-comments.html"]');
       
   438 	if (badge.exists()) {
       
   439 		PyAMS_content.review.timer = setInterval(PyAMS_content.review.updateComments,
       
   440 												 PyAMS_content.review.timer_duration.general);
       
   441 	}
       
   442 
   358 })(jQuery, this);
   443 })(jQuery, this);