text: define(function(require){"use strict";var $=require("jquery"),q=require("js/lib/q"),catalogApi=require("pages/spark-survey/catalogApi"),Backbone=require("backbone"),Readme=require("js/lib/readme"),Coursera=require("pages/spark/app"),_t=require("i18n!pages/spark/views/template/nls/header"),template=require("pages/spark/views/template/header.html"),LearnerStoriesCollection=require("pages/analytics/models/LearnerStoriesCollection"),header=Backbone.View.extend({name:"header",className:"coursera-header",attributes:{role:"menubar"},initialize:function(){this.on("view:appended",function(){if(Coursera.user.canAccessAdmin()||Coursera.user.can("bulk_data_low_risk"))try{var dashboardLink="data/dashboard",onDashboardAlready=-1!==window.location.pathname.indexOf(dashboardLink,window.location.pathname.length-dashboardLink.length);if(!onDashboardAlready){for(var readmeLinks=$("[data-readme=data-dashboard-announcement] a"),i=0;i<readmeLinks.length;i++){var href=window.location.protocol+"//"+window.location.hostname+"/"+Coursera.course.get("sessionName")+"/data/dashboard";$(readmeLinks[i]).attr("href",href)}new Readme("[data-readme]")}}catch(ex){console.error("Failed to announce data/dashboard",ex)}})},render:function(){if(this.$el.html(template({_t:_t,course:Coursera.course,user:Coursera.user,config:Coursera.config})),Coursera.user.canAccessAdmin()){var deferredLearnerStoriesCollection=q.defer(),learnerStoriesCollection=new LearnerStoriesCollection;learnerStoriesCollection.retrieve(function(){deferredLearnerStoriesCollection.resolve()});var sessionId=Coursera.course.get("id"),sessionStartPromise=q(catalogApi.get("sessions?ids="+sessionId+"&fields=startDate"));q.all([sessionStartPromise,deferredLearnerStoriesCollection.promise]).then(function(data){var startDate=data[0].elements[0].startDate;startDate=startDate&&new Date(startDate);var twoWeeksAgo=new Date;twoWeeksAgo.setDate(twoWeeksAgo.getDate()-14);var hasStories=learnerStoriesCollection.size()>0;if(hasStories&&startDate&&twoWeeksAgo>startDate)$(".stories-link").show()})}return this}});return header});