Updating database provider selection UI

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2012-08-23 17:44:58 -07:00
parent 148ada7def
commit 157a5e8f38
11 changed files with 429 additions and 64 deletions
+34 -9
View File
@@ -136,16 +136,34 @@
toggleWhatYouControl: function () {
var _this = $(this);
var _controllees = $("[data-controllerid=" + _this.attr("id") + "]");
var _controlleesAreHidden = _controllees.is(":hidden");
if (_this.is(":checked") || _this.is(":selected")) {
if (_controlleesAreHidden) {
_controllees.hide(); // <- unhook this when the following comment applies
$(_controllees.show()[0]).find("input").focus(); // <- aaaand a slideDown there...eventually
var hide = true;
_controllees.each(function () {
var _controllee = $(this);
var hidden = _controllee.attr("data-defaultstate") == "hidden";
var _controlleeIsHidden = _controllee.is(":hidden");
if (_this.is(":checked") || _this.is(":selected")) {
hide = hidden;
}
} else if (!_controlleesAreHidden) {
//_controllees.slideUp(200); <- hook this back up when chrome behaves, or when I care less...or when chrome behaves
_controllees.hide()
}
else {
hide = !hidden;
}
if (!hide) {
if (_controlleeIsHidden) {
_controllee.hide().show(); // <- unhook this when the following comment applies
}
} else if (!_controlleeIsHidden) {
// _controllees.slideUp(200); // <- hook this back up when chrome behaves, or when I care less...or when chrome behaves
_controllee.hide()
}
});
_controllees.find("input").first().focus(); // <- aaaand a slideDown there...eventually
return _this;
}
});
@@ -170,6 +188,13 @@
controller.toggleWhatYouControl();
});
}
// if data-defaultstate is 'hidden' hide it by default
var hidden = $(this).attr("data-defaultstate") == "hidden";
if (hidden) {
$(this).hide();
}
});
});
// inline form link buttons (form.inline.link button) swapped out for a link that submits said form
@@ -74,15 +74,15 @@ namespace Orchard.Setup.Controllers {
public ActionResult IndexPOST(SetupViewModel model) {
var recipes = OrderRecipes(_setupService.Recipes());
//TODO: Couldn't get a custom ValidationAttribute to validate two properties
if (!model.DatabaseOptions && string.IsNullOrEmpty(model.DatabaseConnectionString))
ModelState.AddModelError("DatabaseConnectionString", T("A SQL connection string is required").Text);
// if no builtin provider, a connection string is mandatory
if (model.DatabaseProvider != SetupDatabaseType.Builtin && string.IsNullOrEmpty(model.DatabaseConnectionString))
ModelState.AddModelError("DatabaseConnectionString", T("A connection string is required").Text);
if (!String.IsNullOrWhiteSpace(model.ConfirmPassword) && model.AdminPassword != model.ConfirmPassword ) {
ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").Text);
}
if(!model.DatabaseOptions && !String.IsNullOrWhiteSpace(model.DatabaseTablePrefix)) {
if (model.DatabaseProvider != SetupDatabaseType.Builtin && !String.IsNullOrWhiteSpace(model.DatabaseTablePrefix)) {
model.DatabaseTablePrefix = model.DatabaseTablePrefix.Trim();
if(!Char.IsLetter(model.DatabaseTablePrefix[0])) {
ModelState.AddModelError("DatabaseTablePrefix", T("The table prefix must begin with a letter").Text);
@@ -113,23 +113,22 @@ namespace Orchard.Setup.Controllers {
try {
string providerName = null;
if (model.DatabaseOptions)
providerName = "SqlCe";
else
switch (model.DatabaseProvider)
{
switch (model.DatabaseType)
{
case SetupDatabaseType.SqlServer:
providerName = "SqlServer";
break;
case SetupDatabaseType.Builtin:
providerName = "SqlCe";
break;
case SetupDatabaseType.MySql:
providerName = "MySql";
break;
case SetupDatabaseType.SqlServer:
providerName = "SqlServer";
break;
default:
throw new ApplicationException("Unknown database type: " + model.DatabaseType);
}
case SetupDatabaseType.MySql:
providerName = "MySql";
break;
default:
throw new ApplicationException("Unknown database type: " + model.DatabaseProvider);
}
var setupContext = new SetupContext {
@@ -7,6 +7,7 @@ namespace Orchard.Setup.Controllers
{
public enum SetupDatabaseType
{
Builtin,
SqlServer,
MySql
}
@@ -13,17 +13,6 @@
}
})();
(function ($) {
$('#databaseType').change(function () {
$('.databaseTypeHint').hide();
$('#databaseType' + $(this).val()).show();
});
// This is to get right info after postback
$('.databaseTypeHint').hide();
$('#databaseType' + $(this).val()).show();
})(jQuery);
(function ($) {
$("select.recipe").change(function () { // class="recipe" on the select element
var description = $(this).find(":selected").attr("recipedescription"); // reads the html attribute of the selected option
@@ -6,7 +6,6 @@ using Orchard.Setup.Controllers;
namespace Orchard.Setup.ViewModels {
public class SetupViewModel {
public SetupViewModel() {
DatabaseOptions = true;
}
[SiteNameValid(maximumLength: 70)]
@@ -17,14 +16,11 @@ namespace Orchard.Setup.ViewModels {
public string AdminPassword { get; set; }
[PasswordConfirmationRequired]
public string ConfirmPassword { get; set; }
public bool DatabaseOptions { get; set; }
public SetupDatabaseType DatabaseProvider { get; set; }
// TODO: Do a better validation of connection string that works with MySQL database connection string also
// [SqlDatabaseConnectionString]
public string DatabaseConnectionString { get; set; }
public string DatabaseTablePrefix { get; set; }
public bool DatabaseIsPreconfigured { get; set; }
public SetupDatabaseType DatabaseType { get; set; }
public IEnumerable<Recipe> Recipes { get; set; }
public string Recipe { get; set; }
@@ -31,31 +31,34 @@ if (!Model.DatabaseIsPreconfigured) {
<legend>@T("How would you like to store your data?")</legend>
@Html.ValidationMessage("DatabaseOptions", "Unable to setup data storage")
<div>
@Html.RadioButtonFor(svm => svm.DatabaseOptions, true, new { id = "builtin" })
@Html.RadioButtonFor(svm => svm.DatabaseProvider, Orchard.Setup.Controllers.SetupDatabaseType.Builtin.ToString(), new { id = "builtin" })
<label for="builtin" class="forcheckbox">@T("Use built-in data storage (SQL Server Compact)")</label>
</div>
<div>
@Html.RadioButtonFor(svm => svm.DatabaseOptions, false, new { id = "sql" })
<label for="sql" class="forcheckbox">@T("Use an existing SQL Server, SQL Express or MySql database")</label>
<div data-controllerid="sql">
<label for="DatabaseProviderName">@T("Database server type")</label>
@Html.DropDownListFor(svm => svm.DatabaseType, Enum.GetValues(typeof(Orchard.Setup.Controllers.SetupDatabaseType)).Cast<Orchard.Setup.Controllers.SetupDatabaseType>().Select(x => new SelectListItem { Text = x.ToString(), Value = ((int)x).ToString() }), new { id = "databaseType" })
</div>
<div data-controllerid="sql">
<label for="DatabaseConnectionString">@T("Connection string")</label>
@Html.EditorFor(svm => svm.DatabaseConnectionString)
<span id="databaseType0" class="hint databaseTypeHint">
@T("SQL Server Example:")<br />@T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password")
</span>
<span id="databaseType1" class="hint databaseTypeHint" style="display: none">
@T("MySQL Example:")<br />@T("Server=MySqlServerName;Port=3306;User Id=UserName;Password=Password;Persist Security Info=True;Database=DatabaseName;Pooling=True;")
</span>
</div>
<div data-controllerid="sql">
<label for="DatabaseTablePrefix">@T("Database Table Prefix")</label>
@Html.EditorFor(svm => svm.DatabaseTablePrefix)
</div>
@Html.RadioButtonFor(svm => svm.DatabaseProvider, Orchard.Setup.Controllers.SetupDatabaseType.SqlServer.ToString(), new { id = "sqlserver" })
<label for="sqlserver" class="forcheckbox">@T("Use an existing SQL Server, SQL Express database")</label>
</div>
<div>
@Html.RadioButtonFor(svm => svm.DatabaseProvider, Orchard.Setup.Controllers.SetupDatabaseType.MySql.ToString(), new { id = "mysql" })
<label for="mysql" class="forcheckbox">@T("Use an existing MySql database")</label>
</div>
<div data-controllerid="builtin" data-defaultstate="hidden">
<label for="DatabaseConnectionString">@T("Connection string")</label>
@Html.EditorFor(svm => svm.DatabaseConnectionString)
<span data-controllerid="sqlserver" class="hint databaseTypeHint">
@T("Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User ID=userName;Password=password")
</span>
<span data-controllerid="mysql" class="hint databaseTypeHint">
@T("Data Source=serverName;Database=dbName;User Id=userName;Password=password")
</span>
<br /><br />
<label for="DatabaseTablePrefix">@T("Database Table Prefix")</label>
@Html.EditorFor(svm => svm.DatabaseTablePrefix)
</div>
</fieldset>
}
<fieldset>