# Source: themes/ess-dive/views/NavbarView.js

    /* global define */
    define(['jquery',
            'views/BaseNavbarView',
            'themes/ess-dive/views/SubmitDataButtonView'],
        function ($, BaseNavbarView, SubmitDataButtonView) {

            /*
             * NavbarView extends the MetacatUI NavbarView and names it BaseNavbarView
             *
             * Build the navbar view of the application
             */
            var NavbarView = BaseNavbarView.extend({
                /**
                 * Override event
                 *
                 * override mouse over event
                 */
                events: {

                            'mouseover .dropdown' : 'showDropdown'
                },

                /**
                 * Override initialize
                 *
                 * Call initialize from base class but
                 * add listener to any changes to email
                 */
                initialize: function () {
                    BaseNavbarView.prototype.initialize.apply(this);

                    this.listenTo(MetacatUI.appUserModel, 'change:email', this.render);
                    this.listenTo(MetacatUI.appUserModel, 'change:isMemberOf', this.render);
                },

                /**
                 * Override render
                 *
                 * Call Render from base class but check if
                 * email is provided
                 */
                render: function () {
                    BaseNavbarView.prototype.render.apply(this);

                    this.checkPermAndEmailProvided();

                    this.$el.html(
                    this.template({
                        username:   MetacatUI.appUserModel.get('username'),
                        formattedName:   MetacatUI.appUserModel.get('firstName'),
                        firstName:  MetacatUI.appUserModel.get('firstName'),
                        loggedIn:   MetacatUI.appUserModel.get("loggedIn"),
                        baseUrl:    MetacatUI.appModel.get('baseUrl')
                    }));

                },

                /**
                 * Check if email is provided by the user.
                 */
                checkPermAndEmailProvided: function () {
                    var elementSubmitData = this.$('li.submitdata');
                    var link = $(elementSubmitData).find("a.btn");
                    $(link).replaceWith(new SubmitDataButtonView({parent:elementSubmitData}).render().el);

                },

                /**
                 * Override showDropdown
                 *
                 * fix the bug when click the nav link menu drop-down remain open
                 */
                showDropdown: function(){
                  //Only show the dropdown menu on hover when not on mobile
                  if($(window).width() < 768) return;

                  $("#menu-main-navigation li").removeClass('open');
                  this.$('.dropdown-menu').removeClass('hidden');
                }

            });

            return NavbarView;
        });