ips.templates.set('core.streams.teaser',"	<li data-action='insertNewItems' class='ipsStreamItem_loadMore ipsBox ipsPadding:half' style='display: none'>		<button class='ipsButton ipsButton_light ipsButton_fullWidth ipsButton_medium'>{{{words}}}</button>	</li>");ips.templates.set('core.streams.unreadBar',"	<li data-role='unreadBar' class='ipsStreamItem_bar'><hr class='ipsHr'></li>");ips.templates.set('core.streams.noMore',"	<li class='ipsType_center ipsType_light ipsType_medium ipsPad' data-role=\"loadMoreContainer\">		{{#lang}}noMoreActivity{{/lang}}	</li>");ips.templates.set('core.streams.loadMore',"	<a href='#' class='ipsButton ipsButton_veryLight ipsButton_small' data-action='loadMore'>{{#lang}}loadNewActivity{{/lang}}</a>");;
;(function($,_,undefined){"use strict";ips.controller.register('core.front.streams.form',{loaded:{},formSnapshot:false,reloaded:false,_loadedContainer:{},_loadedClubs:false,_formData:{},initialize:function(){this.on('streamStateUpdate.streamForm',this.streamStateUpdate);this.on('itemClicked.sideMenu','[data-filterType="type"]',this.selectedType);this.on('menuItemSelected','#elStreamReadStatus, #elStreamShowMe',this.checkFormUpdate);this.on('tokenAdded tokenDeleted',this.tokensChanged);this.on('menuItemSelected','#elStreamSortEdit',this.changeSort);this.on('click','[data-action="saveStream"], [data-action="newStream"]',this.submitForm);this.on('click','[data-role="streamContainer"]',this.openStreamContainer);this.on('click','[data-role="streamClubs"]',this.openStreamClubs);this.on('click','[data-action="dismissSave"]',this.dismissSave);this.on('keydown','input',this.inputKeydown);if(this.scope.attr('data-formType')=='createStream'){this.on('itemClicked.sideMenu','[data-filterType="date"]',this.selectedDate);this.on('itemClicked.sideMenu','[data-filterType="ownership"]',this.selectedOwnership);}else{this.on('menuItemSelected','#elStreamFollowStatus',this.selectedFollowStatus);this.on('menuItemSelected','#elStreamTimePeriod',this.selectedDate);this.on('menuItemSelected','#elStreamOwnership',this.selectedOwnership);}
this.on('change','#elSelect_stream_club_filter',this.clubSelectionChanged);this.on('change','#stream_club_filter_unlimited',this.clubSelectionChanged);this.on('nodeItemSelected',this.toggleApplyFilterButton);this.on('nodeItemUnselected',this.toggleApplyFilterButton);this.on('click','[data-action="applyFilters"]',this.applyFilters);this.on('menuItemSelected','#elStreamSortEdit, #elStreamFollowStatus',this.selectedMenuItem);this.on('menuItemSelected','#elStreamTimePeriod, #elStreamOwnership, #elStreamShowMe',this.selectedMenuItem);this.on('menuItemSelected','#elStreamReadStatus',this.selectedReadStatus);this.on('menuClosed',this.menuClosed);this.setup();},setup:function(){this._serializeConfig={'stream_date_range[start]':this._serializeDate,'stream_date_range[end]':this._serializeDate};if(this.scope.attr('data-formType')!='createStream'){this._formData=ips.getSetting('stream_config');this._changeReadStatus(this._formData['stream_read']);this._updateFilterOverview();this.takeFormSnapshot();}
this.trigger('initialFormData.stream',{data:this._formData});},inputKeydown:function(e){if(e.which==13){e.preventDefault();}},toggleApplyFilterButton:function(e){var button=$('.ipsMenu').filter(':visible').first().find('[data-action="applyFilters"]');if(this.hasFormChanged()){button.removeClass('ipsButton_disabled');}else{button.addClass('ipsButton_disabled');}},applyFilters:function(e){var button=$(e.currentTarget);button.closest('.ipsMenu').trigger('closeMenu');},streamStateUpdate:function(e,data){this._formData=data.filterData;this._updateFieldValues();if(!_.isUndefined(data.hideSaveBar)&&data.hideSaveBar){this.scope.find('[data-role="saveButtonContainer"]').slideUp();}else{this.scope.find('[data-role="saveButtonContainer"]').slideDown();}},_updateFilterOverview:function(){if(this.scope.attr('data-formType')=='createStream'){return;}
var self=this;var values=this._formData;var _overview=function(type){return self.scope.find('[data-filter="'+type+'"] [data-role="filterOverview"]');};_.each(['stream_include_comments','stream_read','stream_sort','stream_solved'],function(val){var lang='streamFilter_'+val+'_'+values[val];_overview(val).html(ips.getString(lang));});if(!_.isUndefined(values['stream_tags'])&&values['stream_tags'].trim()!==''){var tags=_.compact(values['stream_tags'].split(/\n/));if(tags.length<=2){var tagLang=ips.getString('streamFilter_stream_tags_tags',{'tags':_.escape(tags.join(','))});}else{var tagLang=ips.pluralize(ips.getString('streamFilter_stream_tags_count'),tags.length);}
_overview('stream_include_comments').append('; '+tagLang);}else{_overview('stream_include_comments').append('; '+ips.getString('streamFilter_stream_tags_noTags'));}
if(values['stream_ownership']=='custom'&&(_.isUndefined(values['stream_custom_members'])||values['stream_custom_members']==null||values['stream_custom_members']=='')){values['stream_ownership']='all'}
if(values['stream_ownership']!=='custom'){var ownershipLang='streamFilter_stream_ownership_'+values['stream_ownership'];_overview('stream_ownership').html(ips.getString(ownershipLang));}else if(!_.isUndefined(values['stream_custom_members'])&&values['stream_custom_members']!=null){var names=_.compact((_.isObject(values['stream_custom_members'])?values['stream_custom_members']:values['stream_custom_members'].split(/\n/)));var ownershipLang=ips.pluralize(ips.getString('streamFilter_stream_ownership_custom'),names.length);_overview('stream_ownership').text(ownershipLang);}
if(values['stream_follow']=='all'){_overview('stream_follow').html(ips.getString('streamFilter_stream_follow_all'));}else{var value=_.keys(values['stream_followed_types']);var follows=[];for(var i=0;i<value.length;i++){follows.push(ips.getString('streamFilter_stream_follow_'+value[i]));}
_overview('stream_follow').html(follows.join(', '));}
if(values['stream_date_type']=='relative'&&(_.isUndefined(values['stream_date_relative_days'])||values['stream_date_relative_days']==null||values['stream_date_relative_days']=='')){values['stream_date_type']='all';}else if(values['stream_date_type']=='custom'&&((_.isUndefined(values['stream_date_range']['start'])||values['stream_date_range']['start']==null||values['stream_date_range']['start']=='')||(_.isUndefined(values['stream_date_range']['end'])||values['stream_date_range']['end']==null||values['stream_date_range']['end']==''))){values['stream_date_type']='all';}
if(values['stream_date_type']=='all'||values['stream_date_type']=='last_visit'){_overview('stream_date_type').html(ips.getString('streamFilter_stream_date_type_'+values['stream_date_type']));}else if(values['stream_date_type']=='relative'){if(values['stream_date_relative_days']['unit']=='w'){var dateLang=ips.pluralize(ips.getString('streamFilter_stream_date_type_relative_weeks'),(values['stream_date_relative_days']['val']?values['stream_date_relative_days']['val']:values['stream_date_relative_days']));}
else{var dateLang=ips.pluralize(ips.getString('streamFilter_stream_date_type_relative'),(values['stream_date_relative_days']['val']?values['stream_date_relative_days']['val']:values['stream_date_relative_days']));}
_overview('stream_date_type').text(dateLang);}else{if(!_.isUndefined(values['__stream_owner'])||(isNaN(values['stream_date_range']['start'])&&values['stream_date_range']['start'].match('-'))){var start=ips.utils.time.localeDateString(ips.utils.time.removeTimezone(new Date(isNaN(values['stream_date_range']['start'])&&values['stream_date_range']['start'].match('-')?values['stream_date_range']['start']:values['stream_date_range']['start']*1000)));var end=ips.utils.time.localeDateString(ips.utils.time.removeTimezone(new Date(isNaN(values['stream_date_range']['end'])&&values['stream_date_range']['end'].match('-')?values['stream_date_range']['end']:values['stream_date_range']['end']*1000)));}else{var start=ips.utils.time.localeDateString(new Date(values['stream_date_range']['start']*1000));var end=ips.utils.time.localeDateString(new Date(values['stream_date_range']['end']*1000));}
if(!_.isUndefined(values['stream_date_range']['start'])&&!_.isUndefined(values['stream_date_range']['end'])){var dateLang=ips.getString('streamFilter_stream_date_type_range',{start:start,end:end});}else if(!_.isUndefined(values['stream_date_range']['start'])){var dateLang=ips.getString('streamFilter_stream_date_type_start',{start:start});}else if(!_.isUndefined(values['stream_date_range']['start'])){var dateLang=ips.getString('streamFilter_stream_date_type_end',{end:end});}
_overview('stream_date_type').text(dateLang);}
if(!values['stream_classes']||values['stream_classes_type']==0){if(values['stream_club_select']=='none'){_overview('stream_classes').html(ips.getString('streamFilter_stream_classes_no_clubs'));}else if(values['stream_club_select']=='all'){_overview('stream_classes').html(ips.getString('streamFilter_stream_classes_all'));}else if(values['stream_club_filter']){_overview('stream_classes').text(ips.getString('loading'));this._loadClubs(function(){var elem=this.scope.find('#elSelect_stream_club_filter');var clubIds=values['stream_club_filter'].split(',');var clubNames=[];for(var i=0;i<clubIds.length;i++){var option=elem.find('option[value="'+clubIds[i]+'"]');if(option.length){clubNames.push(option.text().trim());}}
_overview('stream_classes').text(clubNames.join(', '));}.bind(this));}}else{var classKeys=_.keys(values['stream_classes']);var classes=[];for(var i=0;i<classKeys.length;i++){var elem=this.scope.find('[data-class="'+classKeys[i].replace(/\\/g,'\\\\')+'"] > span');if(elem.length){classes.push(elem.text().trim());}}
_overview('stream_classes').text(classes.join(', '));}},_updateFieldValues:function(){var self=this;var data=this._formData;if(data['stream_read']=='unread'){data['stream_include_comments']=0;}
_.each(['stream_include_comments','stream_read','stream_sort','stream_follow','stream_ownership','stream_date_type'],function(key){self.scope.find('[name="'+key+'"]').prop('checked',false).closest('.ipsMenu_item').removeClass('ipsMenu_itemChecked').end().filter('[value="'+data[key]+'"]').prop('checked',true).change().closest('.ipsMenu_item').addClass('ipsMenu_itemChecked');});var followSelector=_.map(data['stream_followed_types'],function(val,key){return'[name="stream_followed_types['+key+']"]';});this.scope.find('[name^="stream_followed_types"]').prop('checked',false).closest('.ipsMenu_item').removeClass('ipsMenu_itemChecked').end().filter(followSelector.join(',')).prop('checked',true).change().closest('.ipsMenu_item').addClass('ipsMenu_itemChecked');if(this.scope.find('#elInput_stream_custom_members').length){var ownerAC=ips.ui.autocomplete.getObj(this.scope.find('#elInput_stream_custom_members'));ownerAC.removeAll();if(data['stream_ownership']=='custom'){var names=_.compact(data['stream_custom_members'].split(/\n/));for(var i=0;i<names.length;i++){ownerAC.addToken(names[i]);}}}
if(!_.isUndefined(data['stream_tags'])){var tags=_.compact(data['stream_tags'].split(/\n/));var tagAC=ips.ui.autocomplete.getObj(this.scope.find('#elInput_stream_tags'));tagAC.removeAll();if(tags.length){for(var i=0;i<tags.length;i++){tagAC.addToken(tags[i]);}}}
this.scope.find('[name="stream_date_relative_days"], [name="stream_date_range[start]"], [name="stream_date_range[end]"]').val('');if(data['stream_date_type']=='relative'){this.scope.find('[name="stream_date_relative_days"]').val(data['stream_date_relative_days']);}else if(data['stream_date_type']=='custom'){var html5=ips.utils.time.supportsHTMLDate();if(data['stream_date_range']['start']){var startDateObj=new Date(data['stream_date_range']['start']);if(html5){this.scope.find('[name="stream_date_range[start]"]').get(0).valueAsDate=startDateObj;}else{this.scope.find('[name="stream_date_range[start]"]').datepicker('setDate',ips.utils.time.removeTimezone(startDateObj));}}
if(data['stream_date_range']['end']){var endDateObj=new Date(data['stream_date_range']['end']);if(html5){this.scope.find('[name="stream_date_range[end]"]').get(0).valueAsDate=endDateObj;}else{this.scope.find('[name="stream_date_range[end]"]').datepicker('setDate',ips.utils.time.removeTimezone(endDateObj));}}}
var classChecks=$('#elStreamContentTypes_menu').find('[type="checkbox"][name^="stream_classes"]');var classSelector=[];classChecks.prop('checked',false).change().closest('.ipsSideMenu_item').removeClass('ipsSideMenu_itemActive');if(data['stream_classes_type']==0){this.scope.find('[name="stream_classes_type"]').first().closest('.ipsSideMenu_item').addClass('ipsSideMenu_itemActive');}else{var classKeys=_.keys(data['stream_classes']);_.each(classKeys,function(val){self.scope.find('[data-class="'+val.replace(/\\/g,'\\\\')+'"] input[type="checkbox"]').prop('checked',true).change().closest('.ipsSideMenu_item').addClass('ipsSideMenu_itemActive');});}
this._updateFilterOverview();},openStreamContainer:function(e,data){e.preventDefault();var self=this;var link=$(e.currentTarget);var className=link.attr('data-class');var contentKey=link.attr('data-contentKey');var nodeContainer=link.next('.cStreamForm_nodes');if(!this._loadedContainer[className]){nodeContainer.slideDown();var containers=[];if(_.isObject(ips.getSetting('stream_config'))&&!_.isEmpty(ips.getSetting('stream_config')['containers'])){var keys=_.keys(ips.getSetting('stream_config')['containers']);var values=_.values(ips.getSetting('stream_config')['containers']);for(var i=0;i<keys.length;i++){containers.push('stream_containers['+keys[i]+']='+values[i]);}}
ips.getAjax()(this.scope.find('form').attr('action').replace('do=create',''),{type:'post',data:'do=getContainerNodeElement&className='+className+'&key='+contentKey+'&'+containers.join('&')}).done(function(returnedData){nodeContainer.html(returnedData.node);self._loadedContainer[className]=true;$(document).trigger('contentChange',[nodeContainer.parent()]);});}else{nodeContainer.slideToggle();}},openStreamClubs:function(e,data){e.preventDefault();var clubContainer=$('#elStreamClubs');if(!this._loadedClubs){clubContainer.slideDown();this._loadClubs(null);}else{clubContainer.slideToggle();}},_loadClubs:function(callback){if(!this._loadedClubs){var clubContainer=$('#elStreamClubs');var extra=null;if(_.isObject(ips.getSetting('stream_config'))){extra='&stream_club_select='+ips.getSetting('stream_config')['stream_club_select']+'&stream_club_filter='+ips.getSetting('stream_config')['stream_club_filter'];}
var self=this;ips.getAjax()(this.scope.find('form').attr('action').replace('do=create',''),{type:'post',data:'do=getClubElement&'+extra}).done(function(returnedData){clubContainer.html(returnedData.field);self._loadedClubs=true;$(document).trigger('contentChange',[clubContainer.parent()]);if(callback){callback();}});}else if(callback){callback();}},menuClosed:function(e,data){if(data.elemID=='elStreamContentTypes'||($('#'+data.elemID+'_menu').length&&data.elemID!='elSaveStream')){_.delay(function(self){$('[data-action="applyFilters"]').addClass('ipsButton_disabled');self.checkFormUpdate();self.reloaded=true;},500,this);}},checkFormUpdate:function(){if(this.hasFormChanged()){this.updateResults();this.scope.find('#elSaveStream').removeClass('ipsFaded');this.takeFormSnapshot();}},hasFormChanged:function(){if(_.isEqual(this.formSnapshot,ips.utils.form.serializeAsObject(this.scope.find('form'),this._serializeConfig))){return false;}
return true;},takeFormSnapshot:function(){this.formSnapshot=ips.utils.form.serializeAsObject(this.scope.find('form'),this._serializeConfig);},tokensChanged:function(){this.reloaded=false;},changeSort:function(e,data){this.checkFormUpdate();},selectedMenuItem:function(e,data){if(data.originalEvent){data.originalEvent.preventDefault();}},selectedReadStatus:function(e,data){if(data.originalEvent){data.originalEvent.preventDefault();}
this._changeReadStatus(data.selectedItemID);},_changeReadStatus:function(type){if(type=='unread'){this._formData['stream_include_comments']=0;this.scope.find('#stream_ownership_0').closest('a').trigger('click');this.scope.find('#elStreamShowMe_menu li[data-ipsmenuvalue=1]').addClass('ipsMenu_itemDisabled');}else{this.scope.find('#elStreamShowMe_menu li[data-ipsmenuvalue=1]').removeClass('ipsMenu_itemDisabled');}},dismissSave:function(e){this.scope.find('[data-role="saveButtonContainer"]').slideUp();},submitForm:function(e){var button=$(e.currentTarget);var form=button.closest('form');if(this.scope.attr('data-formType')=='createStream'){return;}
if(button.attr('data-action')=='newStream'){form.prepend($('<input />').attr('type','hidden').attr('name','do').attr('value','create'));}else{this._formData=ips.utils.form.serializeAsObject(this.scope.find('form'),this._serializeConfig);this.trigger('formSubmitted.stream',{data:this._formData,action:(button.attr('data-action')=='newStream')?'createForm':'saveForm'});}},updateResults:function(){this._formData=ips.utils.form.serializeAsObject(this.scope.find('form'),this._serializeConfig);this._updateFilterOverview();this.trigger('formSubmitted.stream',{data:this._formData,action:'updateForm'});},selectedDate:function(e,data){this.reloaded=false;if(data.selectedItemID=='custom'){this.scope.find('[data-role="dateRelativeForm"]').slideUp();this.scope.find('[data-role="dateForm"]').slideDown();}else if(data.selectedItemID=='relative'){this.scope.find('[data-role="dateForm"]').slideUp();this.scope.find('[data-role="dateRelativeForm"]').slideDown();this.scope.find('[name="stream_date_relative_days"]').focus();}else{if(!_.isUndefined(data.selectedItemID)){this.scope.find('[data-role="dateForm"]').slideUp();this.scope.find('[data-role="dateRelativeForm"]').slideUp();this.checkFormUpdate();}}},selectedFollowStatus:function(e,data){var selectedItems=data.selectedItems;if(!_.size(selectedItems)){this.scope.find('[name="stream_follow"]').val('all');}else{this.scope.find('[name="stream_follow"]').val('followed');}
this.checkFormUpdate();},selectedOwnership:function(e,data){if(data.selectedItemID=='custom'){this.scope.find('[data-role="ownershipMemberForm"]').slideDown();}else{if(!_.isUndefined(data.selectedItemID)){this.scope.find('[data-role="ownershipMemberForm"]').slideUp();this.checkFormUpdate();}}},clubSelectionChanged:function(e,data){if(this.scope.find('[name="stream_club_filter_dummy_unlimited"]').is(':checked')){this.scope.find('[name="stream_club_select"]').val('all');}else{this.scope.find('[name="stream_club_select"]').val('select');this.scope.find('[name="stream_club_filter"]').val($('#elSelect_stream_club_filter').val());}
this.toggleApplyFilterButton();},selectedType:function(e,data){var self=this;var typeMenu=this.scope.find('[data-filterType="type"]');var all=typeMenu.find('[data-ipsMenuValue="__all"]');var allButAll=typeMenu.find('[data-ipsMenuValue]:not( [data-ipsMenuValue="__all"] )');var allButAllChecks=allButAll.find('> input[type="checkbox"]');this.reloaded=false;this.toggleApplyFilterButton();if(data.selectedItemID=='__all'){allButAll.removeClass('ipsSideMenu_itemActive').find('> input[type="checkbox"]').prop('checked',false);all.addClass('ipsSideMenu_itemActive');this.scope.find('input[type="radio"][name="stream_classes_type"][value="0"]').prop('checked',true);this.scope.find('[data-contentType]').closest('.cStreamForm_nodes').slideUp();}else{if(allButAllChecks.filter(':checked').length){all.removeClass('ipsSideMenu_itemActive')
this.scope.find('input[type="radio"][name="stream_classes_type"][value="1"]').prop('checked',true);allButAllChecks.filter(':checked').each(function(){var type=$(this).closest('[data-ipsMenuValue]').attr('data-ipsMenuValue');if(self.scope.find('[data-contentType="'+type+'"]').length){self.scope.find('[data-contentType="'+type+'"]').slideDown();}});allButAllChecks.filter(':not( :checked )').each(function(){var type=$(this).closest('[data-ipsMenuValue]').attr('data-ipsMenuValue');if(self.scope.find('[data-contentType="'+type+'"]').length){self.scope.find('[data-contentType="'+type+'"]').slideUp();}})}else{all.addClass('ipsSideMenu_itemActive').find('> input[type="checkbox"]').prop('checked',true);this.scope.find('[data-contentType]').slideUp();}}},_serializeDate:function(name,value){if(ips.utils.time.supportsHTMLDate()){return value;}
var dateObj=ips.utils.time.getDateFromInput($('input[name='+ips.utils.css.escapeSelector(name)+']'));if(!ips.utils.time.isValidDateObj(dateObj)){return'';}
var month=('0'+(dateObj.getUTCMonth()+1)).slice(-2);var day=('0'+(dateObj.getUTCDate())).slice(-2);return dateObj.getUTCFullYear()+'-'+month+'-'+day;}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('core.front.streams.main',{_streamLoadingOverlay:null,_tooltip:null,_tooltipTimer:null,_baseURL:'',_streamID:0,_currentView:'',_shortInterval:15,_longInterval:45,_killUpdate:45,_timer:null,_killTimer:null,_activityUpdate:null,_loadMore:null,_timestamp:0,_autoUpdate:false,_windowFocus:false,initialize:function(){this.on('formSubmitted.stream',this.formSubmitted);this.on('initialFormData.stream',this.initialFormData);this.on('loadMoreResults.stream',this.loadMoreResults);this.on('latestTimestamp.stream',this.latestTimestamp);this.on('click','[data-action="switchView"]',this.switchView);this.on('menuOpened','#elStreamShare',this.menuOpened);this.on('click','[data-action="toggleStreamDefault"]',this.toggleDefault);this.on('click','[data-action="removeStream"]',this.removeStream);this.on('click','[data-action="loadMore"]',this.loadMoreResults);this.on('resultsUpdated.stream',this.resultsUpdated);this.on('stickyStatusChange.sticky','#elStreamFilterForm',this.stickyChange);this.on('click','[data-action="toggleFilters"]',this.toggleFilters);this.on('click','[data-action="subscribe"]',this.subscribe);this.on('click','[data-action="unsubscribe"]',this.unsubscribe);this.on(document,'breakpointChange',this.breakpointChange);this.on(document,'markAllRead',this.markAllRead);this.on(document,ips.utils.events.getVisibilityEvent(),this.windowVisibilityChange);this.on(window,'historychange:streams',this.stateChange);this.setup();},setup:function(){this._streamID=this.scope.attr('data-streamID');this._baseURL=ips.getSetting('stream_config')['url'];if(this._baseURL.match(/\?/)){this._baseURL+='&';}else{this._baseURL+='?';}
if(this._baseURL.slice(-1)=='&'){this._baseURL=this._baseURL.slice(0,-1)}
this._timestamp=parseInt(this.scope.find('[data-timestamp]').first().attr('data-timestamp'));this._currentView=this.scope.find('[data-action="switchView"].ipsButtonRow_active').attr('data-view');if(!_.isUndefined(this.scope.find('[data-role="streamResults"]').attr('data-autoPoll'))){this._autoUpdate=true;this.windowVisibilityChange();}
if(ips.utils.responsive.currentIs('phone')){this.scope.find('[data-role="filterBar"]').addClass('ipsHide');this.scope.find('[data-action="toggleFilters"]').html(ips.getString('toggleFiltersHidden'));}},stateChange:function(){const state={data:ips.utils.history.getState('streams')||{},url:window.location.href,title:document.title}
console.log('updating results')
if((!state.data.controller||state.data.controller!=='core.front.streams.main')&&this._initialURL!==state.url){return;}
if(state.data.action==='saveForm'||state.data.action==='updateForm'){this.triggerOn('core.front.streams.form','streamStateUpdate.streamForm',{filterData:state.data.filterData,hideSaveBar:(_.isEmpty(this._getUrlDiff(state.data.filterData))||state.data.action=='saveForm')});ips.utils.analytics.trackPageView(state.url);if(!_.isUndefined(state.data.filterData.stream_sort)){this._togglePolling(!(state.data.filterData.stream_sort=='oldest'));}
const data=_.extend({view:this._currentView},state.data.filterData);switch(state.data.action){case'updateForm':data.updateOnly=1
break;case'saveForm':data.form='save'
break;}
this._loadResults(data).done((response)=>{this.triggerOn('core.front.streams.results','updateResults.stream',{append:false,response});if(state.data.action==='saveForm'){ips.setSetting('stream_config',JSON.parse(response.config));ips.utils.history.replaceState({controller:'core.front.streams.main',url:ips.getSetting('stream_config')['url'],skipUpdate:true},'core.front.streams.main',ips.getSetting('stream_config').url);}})}else if(state.data.action==='loadMore'){const data=_.extend({before:state.data.before,view:this._currentView},state.data.filters);const before=this.scope.find('[data-role="activityItem"]').last().attr('data-timestamp');this._loadResults(data).done((response)=>{const content=$('<div>'+response.results+'</div>');const latest=parseInt(content.find('[data-role="activityItem"]').last().attr('data-timestamp'))-1;ips.utils.history.replaceState({controller:'core.front.streams.main',latest:latest},'core.front.streams.main',this._buildRequestURL({before:before,latest:isNaN(latest)?0:latest}));this.triggerOn('core.front.streams.results','updateResults.stream',{append:true,response:response,url:this._buildRequestURL({before:before,latest:isNaN(latest)?0:latest})});});}else if(state.data.action==='viewToggle'){this._setViewType(state.data.view);this._loadResults({view:state.data.view,...state.data.filters}).done(response=>this.triggerOn('core.front.streams.results','updateResults.stream',{response}));}else{Debug.log('skip update');}},loadMoreResults:function(e,data){e.preventDefault();var timestamp=this.scope.find('[data-role="activityItem"]').last().attr('data-timestamp');var url=this._buildRequestURL({before:timestamp});this.scope.find('[data-role="loadMoreContainer"] [data-action="loadMore"]').addClass('ipsButton_disabled').text(ips.getString('loading'));ips.utils.history.pushState({controller:'core.front.streams.main',before:timestamp,filters:this._getUrlDiff(this._formData),action:'loadMore'},'streams',url);},toggleFilters:function(e){e.preventDefault();var filterBar=this.scope.find('[data-role="filterBar"]');var toggleButton=$(e.currentTarget);if(filterBar.is(':visible')){filterBar.slideUp();toggleButton.html(ips.getString('toggleFiltersHidden')).removeClass('cStreamFilter_toggleShown');this.scope.find('[data-role="saveButtonContainer"]').addClass('ipsHide');}else{filterBar.slideDown();toggleButton.html(ips.getString('toggleFiltersShown')).addClass('cStreamFilter_toggleShown');}
$(document).trigger('closeMenu');},breakpointChange:function(e,data){if(data.curBreakName=='phone'){this.scope.find('[data-role="filterBar"]').addClass('ipsHide').hide();this.scope.find('[data-action="toggleFilters"]').html(ips.getString('toggleFiltersHidden')).removeClass('cStreamFilter_toggleShown')}else{this.scope.find('[data-role="filterBar"]').removeClass('ipsHide');if(!this.scope.find('[data-role="filterBar"]').is(':visible')){this.scope.find('[data-role="filterBar"]').slideDown();this.scope.find('[data-action="toggleFilters"]').html(ips.getString('toggleFiltersShown')).addClass('cStreamFilter_toggleShown');}}},_setViewType:function(type){this._currentView=type;this.scope.find('[data-action="switchView"]').removeClass('ipsButton_primary').addClass('ipsButton_veryLight').filter('[data-view="'+type+'"]').removeClass('ipsButton_veryLight').addClass('ipsButton_primary');ips.utils.cookie.set('stream_view_'+this._streamID,type,true);},stickyChange:function(e,data){this.scope.find('[data-ipsMenu]').trigger('closeMenu');},switchView:function(e){e.preventDefault();const view=$(e.currentTarget).attr('data-view');ips.utils.history.pushState({controller:'core.front.streams.main',view,filters:this._getUrlDiff(this._formData),action:'viewToggle'},'streams',this._buildRequestURL({view}));},formSubmitted:function(e,data){this._formData=this._getFormData(data.data);const url=this._buildRequestURL();ips.utils.history.pushState({controller:'core.front.streams.main',url:url,filterData:this._formData,action:data.action},'streams',url);},initialFormData:function(e,data){this._formData=this._getFormData(data.data);},latestTimestamp:function(e,data){this._timestamp=data.timestamp;},windowVisibilityChange:function(){var hiddenProp=ips.utils.events.getVisibilityProp();if(!_.isUndefined(hiddenProp)){if(document[hiddenProp]){this._windowFocus=false;this._startTimer(this._longInterval);this._killTimer=setTimeout(_.bind(this._stopPolling,this),this._killUpdate*60*1000);Debug.log("Set the kill timer");}else{this._windowFocus=true;this._startTimer(this._shortInterval);this._updateTitle(0);clearTimeout(this._killTimer);Debug.log("Cleared the kill timer");}}else{this._startTimer(this._longInterval);}},_loadResults:function(data,resetConfig,silent){var self=this;var promise=$.Deferred();if(!silent){this._setStreamLoading(true);}
ips.getAjax()(ips.getSetting('stream_config')['url'],{type:'post',data:data||{}}).done(function(response){if(!silent){self._setStreamLoading(false);self._updateStreamUI(response);}
promise.resolve(response);}).fail(function(response){if(!silent){ips.ui.alert.show({type:'alert',message:ips.getString('errorLoadingStream'),icon:'warn'});}
promise.reject();});return promise;},resultsUpdated:function(e,data){if(this.scope.find('[data-role="activityItem"]').length==0){this.scope.find('[data-role="loadMoreContainer"]').hide();this.scope.find('[data-role="streamContent"]').removeClass('ipsStream_withTimeline');}
else{this.scope.find('[data-role="streamContent"]').addClass('ipsStream_withTimeline');this.scope.find('[data-role="loadMoreContainer"]').show();}},_updateStreamUI:function(response){Debug.log("Updating stream UI...");this.scope.find('[data-role="streamBlurb"]').text(response.blurb.replace(/&#039;/g,"'"));this.scope.find('[data-role="streamTitle"]').html(response.title);if(response.count==0){this.scope.find('[data-role="loadMoreContainer"]').show().html(ips.templates.render('core.streams.noMore'));}else{this.scope.find('[data-role="loadMoreContainer"]').show().html(ips.templates.render('core.streams.loadMore'));}
if(response.id){var menuItem=$('body').find('[data-streamid="'+response.id+'"] > a');menuItem.html(response.title);}},_getFormData:function(data){var returnValues={};_.each(data,function(val,key){if(key.startsWith('stream_')){returnValues[key]=val;}});try{if(!_.isUndefined(returnValues['stream_classes']['__EMPTY'])){returnValues['stream_classes']=_.omit(returnValues['stream_classes'],'__EMPTY');}}catch(err){}
return returnValues;},_getUrlDiff:function(data){var returnedValues={};var defaultValues=ips.getSetting('stream_config');if(!_.isUndefined(defaultValues['changed'])){_.each(defaultValues['changed'],function(val,key){returnedValues[(key=='containers')?'stream_containers':key]=defaultValues[key];});}
if(!_.size(data)){return returnedValues;}
_.each(['stream_sort','stream_include_comments','stream_read','stream_default_view','stream_club_select','stream_club_filter'],function(val){if(defaultValues[val]!=data[val]&&!_.isUndefined(data[val])){returnedValues[val]=data[val];}});if(data['stream_ownership']=='custom'){var newNames=_.isObject(data['stream_custom_members'])?data['stream_custom_members']:data['stream_custom_members'].split(/\n/);var oldNames=defaultValues['stream_custom_members'];if(!_.isObject(oldNames)){oldNames=[];}
var nameIntersection=_.intersection(newNames,oldNames);if(!newNames.length){returnedValues['stream_ownership']='all';}
else if(newNames.length!==oldNames.length||nameIntersection.length!==newNames.length){returnedValues['stream_ownership']='custom';returnedValues['stream_custom_members']=data['stream_custom_members'];}}else if(defaultValues['stream_ownership']!==data['stream_ownership']){returnedValues['stream_ownership']=data['stream_ownership'];}
if(!(defaultValues['stream_follow']=='all'&&data['stream_follow']=='all')){if(data['stream_follow']=='followed'){var newFollowTypes=_.keys(data['stream_followed_types']);var oldFollowTypes=_.keys(defaultValues['stream_followed_types']);var followIntersection=_.intersection(newFollowTypes,oldFollowTypes);if(newFollowTypes.length!==oldFollowTypes.length||followIntersection.length!==newFollowTypes.length){returnedValues['stream_follow']='followed';returnedValues['stream_followed_types']=data['stream_followed_types'];}}else{returnedValues['stream_follow']=data['stream_follow'];}}
if(!_.isUndefined(data['stream_tags'])&&!_.isEmpty(data['stream_tags'].trim())){var newTags=_.compact((data['stream_tags']||'').split(/\n/));var oldTags=_.compact((defaultValues['stream_tags']||'').split(/\n/));var tagIntersection=_.intersection(newTags,defaultValues['stream_tags']);if(newTags.length!==oldTags.length||tagIntersection.length!==newTags.length){returnedValues['stream_tags']=_.map(newTags,function(str){return str.trim()}).join(',');}}else if(defaultValues['stream_tags']){returnedValues['stream_tags']='';}
if(data['stream_date_type']=='custom'){var startTest=data['stream_date_range']['start'];if(startTest.toString().match(/^[0-9]{9,10}$/)){var start=data['stream_date_range']['start'];var end=data['stream_date_range']['end'];}
else
{var start=new Date(data['stream_date_range']['start']).getTime()/1000;var end=new Date(data['stream_date_range']['end']).getTime()/1000;}
if(data['stream_date_range']['start']&&(_.isUndefined(defaultValues['stream_date_range'])||start!==defaultValues['stream_date_range']['start'])){returnedValues['stream_date_type']='custom';returnedValues['stream_date_start']=start;}
if(data['stream_date_range']['end']&&(_.isUndefined(defaultValues['stream_date_range'])||end!==defaultValues['stream_date_range']['end'])){returnedValues['stream_date_type']='custom';returnedValues['stream_date_end']=end;}}else if(data['stream_date_type']=='relative'){if(defaultValues['stream_date_relative_days']!==data['stream_date_relative_days']){returnedValues['stream_date_type']='relative';returnedValues['stream_date_relative_days']=data['stream_date_relative_days'];}}else if(defaultValues['stream_date_type']!==data['stream_date_type']){returnedValues['stream_date_type']=data['stream_date_type'];}
if(data['stream_classes_type']==0&&defaultValues['stream_classes_type']==1){returnedValues['stream_classes']={};}else{var newClasses=_.without(_.keys(data['stream_classes']),'__EMPTY');var classIntersection=_.intersection(newClasses,_.keys(defaultValues['stream_classes']));if(classIntersection.length!==newClasses.length){returnedValues['stream_classes']=_.omit(data['stream_classes'],'__EMPTY');}}
var containers={};if(!_.isUndefined(data['stream_classes'])&&_.isObject(data['stream_classes'])){_.each(_.without(_.keys(data['stream_classes']),'__EMPTY'),function(val,key){var contentType=$('div[data-role="streamContainer"][data-className="'+val.replace(/\\/g,'\\\\')+'"]').attr('data-contentKey');if(!_.isUndefined(contentType)&&$('input[name="stream_containers_'+contentType+'"]').length){containers[val]=$('input[name="stream_containers_'+contentType+'"]').val();}});}
if(!_.isEmpty(containers)){if(!_.isUndefined(defaultValues['containers'])&&!_.isEqual(containers,defaultValues['containers'])){returnedValues['stream_containers']=containers;}}
return returnedValues;},_buildRequestURL:function(extraParams){var urlDiff=this._getUrlDiff(this._formData);var params=[];_.each(urlDiff,function(val,key){if(_.isObject(val)){if(!_.size(val)){params.push(key+'=');}else{var keys=_.keys(val);var values=_.values(val);for(var i=0;i<keys.length;i++){var paramValue=(!_.isUndefined(values[i])?values[i]:1);params.push(key+'['+encodeURIComponent(keys[i])+']='+paramValue);}}}else{params.push(key+'='+encodeURIComponent(val));}});if(_.isObject(extraParams)){_.each(extraParams,function(val,key){params.push(key+'='+encodeURIComponent(val));});}
return this._baseURL+'&'+params.join('&');},menuOpened:function(e,data){data.menu.find('input[type="text"]').focus().get(0).select();},removeStream:function(e){e.preventDefault();ips.ui.alert.show({type:'confirm',message:ips.getString('confirmRemoveStream'),callbacks:{ok:function(){window.location=$(e.currentTarget).attr('href')+'&wasConfirmed=1';},}});},toggleDefault:function(e){e.preventDefault();var self=this;var link=$(e.currentTarget);var value=link.attr('data-change');var url=link.attr('href');ips.getAjax()(url).done(function(response){if(value==1){self.scope.find('a[data-action="toggleStreamDefault"][data-change="0"]').removeClass('ipsHide');self.scope.find('a[data-action="toggleStreamDefault"][data-change="1"]').addClass('ipsHide');}else{self.scope.find('a[data-action="toggleStreamDefault"][data-change="0"]').addClass('ipsHide');self.scope.find('a[data-action="toggleStreamDefault"][data-change="1"]').removeClass('ipsHide');}
if(!response.title){$('a[data-action="defaultStream"]').hide();}else{$('a[data-action="defaultStream"]').attr('href',response.url).show().find('span').html(response.title);}
if(value==1){if(!ips.utils.responsive.enabled||!ips.utils.responsive.currentIs('phone')&&$('a[data-action="defaultStream"]').is(':visible')){self._showStreamTooltip(response.tooltip);}else{ips.utils.anim.go('pulseOnce',$('a[data-action="defaultStream"]'));}}});},_showStreamTooltip:function(title){if(!this._tooltip){var tooltipHTML=ips.templates.render('core.tooltip',{id:'elDefaultStreamTooltip_'+this.controllerID});ips.getContainer().append(tooltipHTML);this._tooltip=$('#elDefaultStreamTooltip_'+this.controllerID);}else{this._tooltip.hide();}
if(this._tooltipTimer){clearTimeout(this._tooltipTimer);}
this._tooltip.text(ips.getString('streamDefaultTooltip',{title:title}));var streamLink=$('a[data-action="defaultStream"]:visible');var self=this;var positionInfo={trigger:streamLink.first(),target:this._tooltip,center:true,above:true};var tooltipPosition=ips.utils.position.positionElem(positionInfo);$(this._tooltip).css({left:tooltipPosition.left+'px',top:tooltipPosition.top+'px',position:(tooltipPosition.fixed)?'fixed':'absolute',zIndex:ips.ui.zIndex()});if(tooltipPosition.location.vertical=='top'){this._tooltip.addClass('ipsTooltip_top');}else{this._tooltip.addClass('ipsTooltip_bottom');}
this._tooltip.show();setTimeout(function(){if(self._tooltip&&self._tooltip.is(':visible')){ips.utils.anim.go('fadeOut',self._tooltip);}},3000);},_setStreamLoading:function(loading){var stream=this.scope.find('[data-role="streamContent"]');if(!loading){this._streamLoadingOverlay.hide();stream.css({opacity:"1"});return;}else{if(!this._streamLoadingOverlay){this._streamLoadingOverlay=$('<div/>').addClass('ipsLoading');ips.getContainer().append(this._streamLoadingOverlay);}
var dims=ips.utils.position.getElemDims(stream);var position=ips.utils.position.getElemPosition(stream);this._streamLoadingOverlay.show().css({left:position.viewportOffset.left+'px',top:position.viewportOffset.top+$(document).scrollTop()+'px',width:dims.width+'px',height:dims.height+'px',position:'absolute',zIndex:ips.ui.zIndex()});stream.css({opacity:"0.5"});}},_startTimer:function(interval){if(!this._autoUpdate){return;}
if(!interval){interval=this._shortInterval;}
if(this._timer){clearInterval(this._timer);}
this._timer=setInterval(_.bind(this._autoFetchNew,this),interval*1000);},_togglePolling:function(status){if(!this._autoUpdate){clearInterval(this._timer);return;}
if(status){this._startTimer();this.scope.find('[data-role="updateMessage"]').show();}else{if(this._timer){clearInterval(this._timer);this.scope.find('[data-role="updateMessage"]').hide();}}},_autoFetchNew:function(){var self=this;if(!_.isNumber(this._timestamp)||_.isNaN(this._timestamp)){Debug.log("Timestamp not a number");clearInterval(this._timer);return;}
this._loadResults({after:this._timestamp},false,true).done(function(response){var count=parseInt(response.count);if(response.error&&response.error=='auto_polling_disabled'){self.scope.find('[data-role="updateMessage"]').remove();clearInterval(self._timer);return;}
if(_.isNaN(count)||count==0){return;}
self.triggerOn('core.front.streams.results','resultsTeaser.stream',{response:response});});},_stopPolling:function(){clearInterval(this._timer);this._autoUpdate=false;this.scope.find('[data-role="updateMessage"]').html(ips.getString('autoUpdateStopped'));Debug.log("Stopped polling due to user inactivity");},_updateTitle:function(count){},markAllRead:function(){this.scope.find('.ipsStreamItem_unread').removeClass('ipsStreamItem_unread').find('.ipsItemStatus:not(.ipsItemStatus_read)').addClass('ipsItemStatus_read');}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('core.front.streams.results',{_streamID:0,_newUpdates:$('<div/>'),_waitingCount:0,_config:{},initialize:function(){this.on('updateResults.stream',this.updateResults);this.on('resultsTeaser.stream',this.resultsTeaser);this.on('click','[data-action="insertNewItems"]',this.insertNewItems);this.on('click','a[data-linkType]',this.clickResult);this.setup();},setup:function(){if(this.scope.attr('data-streamID')){this._streamID=this.scope.attr('data-streamID');}
this._config=ips.getSetting('stream_config');},updateResults:function(e,data){if(data.append){this._appendNewResults(data);}else{this._replaceWithNewResults(data);}},_replaceWithNewResults:function(data){this._config=JSON.parse(data.response.config);if(data.response.results.indexOf('core.front.streams.results')!==-1){var content=$('<div>'+data.response.results+'</div>');var root=content.find('[data-controller="core.front.streams.results"]');this.cleanContents();this.scope.html(root.html()).attr('data-streamReadType',root.attr('data-streamReadType')).attr('data-streamURL',root.attr('data-streamURL')).attr('data-streamID',root.attr('data-streamID'));}else{ips.controller.cleanContentsOf(this.scope.find('[data-role="streamContent"]'));this.scope.find('[data-role="streamContent"]').html(data.response.results);}
this.trigger('resultsUpdated.stream',{response:data.response});$(document).trigger('contentChange',[this.scope]);},_appendNewResults:function(data){var content=$('<div>'+data.response.results+'</div>');var latestBubble=this.scope.find('[data-timeType]').last().attr('data-timeType');content.find('[data-timeType="'+latestBubble+'"]').remove();content.find('[data-role="activityItem"]').attr('data-new',true).css({opacity:"0"});if(!_.isUndefined(data.url)){content.find('.ipsComment_content form[action="'+this._config['url']+'"]').attr('action',data.url);}
var existingItems=this.scope.find('[data-role="activityItem"]');var count=existingItems.length;existingItems.last().after(content);this.scope.find('[data-role="activityItem"]').slice(count).each(function(){$(document).trigger('contentChange',[$(this)]);});this._animateNewItems();},clickResult:function(e,data){var item=$(e.target).closest('[data-indexID]');var star=item.find('a[data-linkType="star"]');this.scope.find('.ipsStreamItem_active').removeClass('ipsStreamItem_active');item.addClass('ipsStreamItem_active').find('.ipsStreamItem_unread').removeClass('ipsStreamItem_unread');if(star.attr('data-iPostedIn')){star.find('span.ipsItemStatus').addClass('ipsItemStatus_read').addClass('ipsItemStatus_posted').unwrap();}else{star.addClass('ipsHide');}},insertNewItems:function(e){e.preventDefault();var insertBefore=null;if(this.scope.find('[data-timeType="past_hour"]').length){insertBefore=this.scope.find('[data-timeType="past_hour"]').siblings('[data-role="activityItem"]').first();this._newUpdates.find('[data-timeType]').remove();}else{insertBefore=this.scope.find('[data-timeType], [data-role="activityItem"]').first();}
this.scope.find('[data-role="unreadBar"]').remove();this._newUpdates.append(ips.templates.render('core.streams.unreadBar'));this._newUpdates.find('[data-role="activityItem"]').attr('data-new',true).css({opacity:"0"});insertBefore.before(this._newUpdates.html());$(document).trigger('contentChange',[this.scope]);this.scope.find('[data-action="insertNewItems"]').remove();this._animateNewItems();this._newUpdates=$('<div/>');this._waitingCount=0;},_animateNewItems:function(){var newItems=this.scope.find('[data-new]');var delay=200;newItems.each(function(index){var d=(index*delay);$(this).delay((d>1200)?1200:d).animate({opacity:"1"}).removeAttr('data-new');});},resultsTeaser:function(e,data){var self=this;var response=data.response;var count=parseInt(response.count);var tmp=$('<div>'+response.results+'</div>');self.trigger('latestTimestamp.stream',{timestamp:parseInt(tmp.find('[data-timestamp]').first().attr('data-timestamp'))});self._waitingCount+=count;if(tmp.find('[data-timeType]').length){var type=tmp.find('[data-timeType]').attr('data-timeType');self._newUpdates.find('[data-timeType="'+type+'"]').remove();}
self._newUpdates.prepend(tmp.contents());var teaser=ips.templates.render('core.streams.teaser',{count:self._waitingCount,words:ips.pluralize(ips.getString('newActivityItems'),[self._waitingCount,self._waitingCount])});if(self.scope.find('[data-action="insertNewItems"]').length){self.scope.find('[data-action="insertNewItems"]').replaceWith(teaser);self.scope.find('[data-action="insertNewItems"]').show();}else{self.scope.find('[data-role="activityItem"]').first().before(teaser);self.scope.find('[data-action="insertNewItems"]').slideDown();}}});}(jQuery,_));;