src/preferences/PreferencesDialogs.js
function showProjectPreferencesDialog(baseUrl, errorMessage) {
        var $baseUrlControl,
            dialog;

        // Title
        var projectName = "",
            projectRoot = ProjectManager.getProjectRoot(),
            title;
        if (projectRoot) {
            projectName = projectRoot.name;
        }
        title = StringUtils.format(Strings.PROJECT_SETTINGS_TITLE, projectName);

        var templateVars = {
            title        : title,
            baseUrl      : baseUrl,
            errorMessage : errorMessage,
            Strings      : Strings
        };

        dialog = Dialogs.showModalDialogUsingTemplate(Mustache.render(SettingsDialogTemplate, templateVars));

        dialog.done(function (id) {
            if (id === Dialogs.DIALOG_BTN_OK) {
                var baseUrlValue = $baseUrlControl.val();
                var result = _validateBaseUrl(baseUrlValue);
                if (result === "") {
                    // Send analytics data when url is set in project settings
                    HealthLogger.sendAnalyticsData(
                        "projectSettingsLivepreview",
                        "usage",
                        "projectSettings",
                        "use"
                    );
                    ProjectManager.setBaseUrl(baseUrlValue);
                } else {
                    // Re-invoke dialog with result (error message)
                    showProjectPreferencesDialog(baseUrlValue, result);
                }
            }
        });

        // Give focus to first control
        $baseUrlControl = dialog.getElement().find(".url");
        $baseUrlControl.focus();

        return dialog;
    }
function showProjectPreferencesDialog(baseUrl, errorMessage) {
        var $baseUrlControl,
            dialog;

        // Title
        var projectName = "",
            projectRoot = ProjectManager.getProjectRoot(),
            title;
        if (projectRoot) {
            projectName = projectRoot.name;
        }
        title = StringUtils.format(Strings.PROJECT_SETTINGS_TITLE, projectName);

        var templateVars = {
            title        : title,
            baseUrl      : baseUrl,
            errorMessage : errorMessage,
            Strings      : Strings
        };

        dialog = Dialogs.showModalDialogUsingTemplate(Mustache.render(SettingsDialogTemplate, templateVars));

        dialog.done(function (id) {
            if (id === Dialogs.DIALOG_BTN_OK) {
                var baseUrlValue = $baseUrlControl.val();
                var result = _validateBaseUrl(baseUrlValue);
                if (result === "") {
                    // Send analytics data when url is set in project settings
                    HealthLogger.sendAnalyticsData(
                        "projectSettingsLivepreview",
                        "usage",
                        "projectSettings",
                        "use"
                    );
                    ProjectManager.setBaseUrl(baseUrlValue);
                } else {
                    // Re-invoke dialog with result (error message)
                    showProjectPreferencesDialog(baseUrlValue, result);
                }
            }
        });

        // Give focus to first control
        $baseUrlControl = dialog.getElement().find(".url");
        $baseUrlControl.focus();

        return dialog;
    }
function showProjectPreferencesDialog ( baseUrl , errorMessage ) { var $baseUrlControl , dialog ; // Title var projectName = "" , projectRoot = ProjectManager . getProjectRoot ( ) , title ; if ( projectRoot ) { projectName = projectRoot . name ; } title = StringUtils . format ( Strings . PROJECT_SETTINGS_TITLE , projectName ) ; var templateVars = { title : title , baseUrl : baseUrl , errorMessage : errorMessage , Strings : Strings } ; dialog = Dialogs . showModalDialogUsingTemplate ( Mustache . render ( SettingsDialogTemplate , templateVars ) ) ; dialog . done ( function ( id ) { if ( id === Dialogs . DIALOG_BTN_OK ) { var baseUrlValue = $baseUrlControl . val ( ) ; var result = _validateBaseUrl ( baseUrlValue ) ; if ( result === "" ) { // Send analytics data when url is set in project settings HealthLogger . sendAnalyticsData ( "projectSettingsLivepreview" , "usage" , "projectSettings" , "use" ) ; ProjectManager . setBaseUrl ( baseUrlValue ) ; } else { // Re-invoke dialog with result (error message) showProjectPreferencesDialog ( baseUrlValue , result ) ; } } } ) ; // Give focus to first control $baseUrlControl = dialog . getElement ( ) . find ( ".url" ) ; $baseUrlControl . focus ( ) ; return dialog ; }
Show a dialog that shows the project preferences
@param {string} baseUrl Initial value
@param {string} errorMessage Error to display
@return {Dialog} A Dialog object with an internal promise that will be resolved with the ID
of the clicked button when the dialog is dismissed. Never rejected.
Show a dialog that shows the project preferences