重构代码:更新Settings网页代码

This commit is contained in:
Argo-MacBookPro 2018-06-07 12:49:59 +08:00
parent 72c0e47e6f
commit 80e8055d67
2 changed files with 48 additions and 72 deletions

View File

@ -6,6 +6,7 @@
@section Javascript { @section Javascript {
<script src="~/js/longbow.dataentity.js"></script> <script src="~/js/longbow.dataentity.js"></script>
<script src="~/js/jquery.validate.js"></script> <script src="~/js/jquery.validate.js"></script>
<script src="~/js/longbow.validate.js"></script>
<script src="~/js/messages_zh.js"></script> <script src="~/js/messages_zh.js"></script>
<script src="~/js/Settings.js"></script> <script src="~/js/Settings.js"></script>
} }
@ -14,28 +15,24 @@
} }
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">系统名称设置</div> <div class="panel-heading">系统名称设置</div>
<div class="panel-body"> <div class="panel-body" data-toggle="LgbValidate" data-valid-button="#sysSave">
<form id="headerDataForm" name="headerDataForm"> <div class="input-group form-group col-xs-12">
<div class="input-group form-group col-xs-12"> <input type="text" class="form-control" id="sysName" placeholder="请输入网站标题50字以内" value="@Model.Title" maxlength="50" data-valid="true" />
<input type="text" class="form-control" id="sysName" name="sysName" placeholder="请输入网站标题50字以内" value="@Model.Title" maxlength="50" /> <span class="input-group-btn">
<span class="input-group-btn"> <button class="btn btn-default" type="button" data-method="title">保存</button>
<button class="btn btn-default" type="button" id="sysSave">保存</button> </span>
</span> </div>
</div>
</form>
</div> </div>
</div> </div>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">页脚设置</div> <div class="panel-heading">页脚设置</div>
<div class="panel-body"> <div class="panel-body" data-toggle="LgbValidate" data-valid-button="#footSave">
<form id="footerDataForm" name="footerDataForm"> <div class="input-group form-group col-xs-12">
<div class="input-group form-group col-xs-12"> <input type="text" class="form-control" id="sysFoot" placeholder="请输入网站页脚50字以内" value="@Model.Footer" maxlength="50" data-valid="true" />
<input type="text" class="form-control" id="sysFoot" name="sysFoot" placeholder="请输入网站页脚50字以内" value="@Model.Footer" maxlength="50" /> <span class="input-group-btn">
<span class="input-group-btn"> <button class="btn btn-default" type="button" data-method="footer">保存</button>
<button class="btn btn-default" type="button" id="footSave">保存</button> </span>
</span> </div>
</div>
</form>
</div> </div>
</div> </div>
<div class="panel panel-default"> <div class="panel panel-default">
@ -54,7 +51,7 @@
<li><a href="#" data-val="">默认样式</a></li> <li><a href="#" data-val="">默认样式</a></li>
</ul> </ul>
</div> </div>
<button class="btn btn-default pull-right" type="button" id="cssSave">保存</button> <button class="btn btn-default pull-right" type="button" data-method="css">保存</button>
</div> </div>
</div> </div>
</form> </form>

View File

@ -1,21 +1,5 @@
$(function () { $(function () {
$('a[data-admin="False"]').hide(); $('a[data-admin="False"]').hide();
$('#headerDataForm').autoValidate({
sysName: {
required: true,
maxlength: 50
}
}, {
button: ['sysSave']
});
$('#footerDataForm').autoValidate({
sysFoot: {
required: true,
maxlength: 50
}
}, {
button: ['footSave']
});
var bsa = new BootstrapAdmin({ var bsa = new BootstrapAdmin({
url: Settings.url, url: Settings.url,
@ -27,46 +11,41 @@
Title: "sysName", Title: "sysName",
Footer: "sysFoot" Footer: "sysFoot"
} }
}), })
click: { });
assign: [{
id: 'sysSave', $('button[data-method]').on('click', function (e) {
click: function (row, data) { var $this = $(this);
if ($(this).attr('data-valid') == "true") { switch ($this.attr('data-method')) {
$.bc({ case 'footer':
url: Settings.url, data: { name: '网站标题', code: data.Title, category: Settings.title }, title: Settings.title, var data = bsa.dataEntity.get();
callback: function (result) { $.bc({
if (result) $('#websiteTitle').text(data.Title); url: Settings.url, data: { name: '网站页脚', code: data.Footer, category: Settings.title }, title: Settings.title,
} callback: function (result) {
}); if (result) $('#websiteFooter').text(data.Footer);
} }
} });
}, { break;
id: 'footSave', case 'title':
click: function (row, data) { var data = bsa.dataEntity.get();
if ($(this).attr('data-valid') == "true") { $.bc({
$.bc({ url: Settings.url, data: { name: '网站标题', code: data.Title, category: Settings.title }, title: Settings.title,
url: Settings.url, data: { name: '网站页脚', code: data.Footer, category: Settings.title }, title: Settings.title, callback: function (result) {
callback: function (result) { if (result) $('#websiteTitle').text(data.Title);
if (result) $('#websiteFooter').text(data.Footer);
}
});
} }
} });
}, { break;
id: 'cssSave', case 'css':
click: function (row, data) { var cssDefine = $('#dictCssDefine').val();
var cssDefine = $('#dictCssDefine').val(); $.bc({
$.bc({ url: Settings.url, data: { name: '使用样式', code: cssDefine, category: '当前样式' }, title: '网站样式',
url: Settings.url, data: { name: '使用样式', code: cssDefine, category: '当前样式' }, title: '网站样式', callback: function (result) {
callback: function (result) { if (result) {
if (result) { window.setTimeout(function () { window.location.reload(true); }, 1000);
window.setTimeout(function () { window.location.reload(true); }, 1000);
}
} }
}); }
} });
}] break;
} }
}); });