forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPreferencesDialogs.js
More file actions
1 lines (1 loc) · 1.97 KB
/
Copy pathPreferencesDialogs.js
File metadata and controls
1 lines (1 loc) · 1.97 KB
1
define(function(require,exports,module){var Dialogs=require("widgets/Dialogs"),ProjectManager=require("project/ProjectManager"),StringUtils=require("utils/StringUtils"),Strings=require("strings"),SettingsDialogTemplate=require("text!htmlContent/project-settings-dialog.html"),Mustache=require("thirdparty/mustache/mustache"),PathUtils=require("thirdparty/path-utils/path-utils"),Metrics=require("utils/Metrics");function _validateBaseUrl(url){var result="";if(""===url)return result;var obj=PathUtils.parseUrl(url);if(obj)if(0!==obj.href.search(/^(http|https):\/\//i))result=StringUtils.format(Strings.BASEURL_ERROR_INVALID_PROTOCOL,obj.href.substring(0,obj.href.indexOf("//")));else if(""!==obj.search)result=StringUtils.format(Strings.BASEURL_ERROR_SEARCH_DISALLOWED,obj.search);else if(""!==obj.hash)result=StringUtils.format(Strings.BASEURL_ERROR_HASH_DISALLOWED,obj.hash);else{var index=url.search(/[ \^\[\]\{\}<>\\"\?]+/);-1!==index&&(result=StringUtils.format(Strings.BASEURL_ERROR_INVALID_CHAR,url[index]))}else result=Strings.BASEURL_ERROR_UNKNOWN_ERROR;return result}function showProjectPreferencesDialog(baseUrl,errorMessage){var $baseUrlControl,dialog,projectName="",projectRoot=ProjectManager.getProjectRoot(),title;projectRoot&&(projectName=projectRoot.name);var templateVars={title:title=StringUtils.format(Strings.PROJECT_SETTINGS_TITLE,projectName),baseUrl:baseUrl,errorMessage:errorMessage,Strings:Strings};return(dialog=Dialogs.showModalDialogUsingTemplate(Mustache.render(SettingsDialogTemplate,templateVars))).done(function(id){if(id===Dialogs.DIALOG_BTN_OK){var baseUrlValue=$baseUrlControl.val(),result=_validateBaseUrl(baseUrlValue);""===result?(Metrics.countEvent(Metrics.EVENT_TYPE.UI_DIALOG,"projectSettings","Livepreview"),ProjectManager.setBaseUrl(baseUrlValue)):showProjectPreferencesDialog(baseUrlValue,result)}}),($baseUrlControl=dialog.getElement().find(".url")).focus(),dialog}exports._validateBaseUrl=_validateBaseUrl,exports.showProjectPreferencesDialog=showProjectPreferencesDialog});