js模块化开发主要是 模拟高级语言类的慨念,是各个js 之间 清晰明确:
1 //地点人物关系类 2 (Book = new function () { 3 this.TypeWay= "Post"; 4 this.FormType = 0;//默认0:PersonLocations,1:BookLocations表 5 this.BookID = emptyGuid; 6 this.CurRelationRows=null; 7 this.gridItemId = ""; 8 9 //绑定事件 10 this.BindClick = function () { 11 12 $('#imgBox').on('mouseover', '.upimg-item', function () { 13 $(this).find('.remove').show(); 14 }); 15 16 $('#imgBox').on('mouseout', '.upimg-item', function () { 17 $(this).find('.remove').hide(); 18 }); 19 20 $('#imgBox').on('click', '.remove', function () { 21 var imgId = $(this).next().attr('Id'); 22 var parent = $(this).parent().remove(); 23 var imgJsonArray = JSON.parse($('#Images').val()); 24 imgJsonArray = spliceJsonObject(imgId, imgJsonArray); 25 var imgsText = JSON.stringify(imgJsonArray); 26 $('#Images').val(imgsText); 27 //showImgs('imgBox', imgJsonArray); 28 }); 29 30 $('#imgBox').on('dblclick', '.img', function () { 31 var imgId = $(this).attr('Id'); 32 Global.EditingImgId = imgId; 33 34 var imgJsonArray = JSON.parse($('#Images').val()); 35 var jsonObject = findJsonObjectById(imgId, imgJsonArray); 36 $('#imgDate').val(jsonObject.Date); 37 $('#imgDescription').val(jsonObject.Desc); 38 $('#ImageId').val(jsonObject.Id); 39 40 $("#uploadImgDialog").dialog("open"); 41 }); 42 43 //新增用户 44 $("#btn_create").click(function () { 45 46 Book.AddRow("#BooksDialog", true); 47 }); 48 49 $("#addImg").on("click", function () { 50 $("#uploadImgDialog").dialog("open"); 51 }); 52 53 $('.resource-form').on('change', 'input[type="file"]', function () { 54 var files = document.getElementById("ImageUpload"); 55 var filesize = 0; 56 var fileVal = files.value; 57 if (/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(fileVal)) { 58 setTimeout(function () { 59 $.uploadImg('resource-form'); 60 }, 10); 61 } else { 62 $('.upload-fail-cont,.dialog-img-bg').show(); 63 $('.upload-fail-cont').find('p').text('图片格式有误,请上传png,jpg/jpeg格式'); 64 $('.share-cont').hide(); 65 return; 66 } 67 }); 68 69 $('#TagIds').multiselect({ 70 enableFiltering: true, 71 buttonWidth: '280px' 72 }); 73 74 } 75 76 //初始化页面 77 this.Init = function () { 78 79 Book.BuildUsersGrid(); 80 $("#BooksDialog").dialog({ 81 autoOpen: false, 82 width: 600, 83 height: 700, 84 modal: true, 85 resizable: false, 86 buttons: [ 87 { 88 id: 'user-ok', 89 text: '确定', 90 click: function () { 91 var tagIds = $.getAllSelectedValue('TagIds'); 92 var _param = { 93 Id: Book.BookID, 94 AuthorId: $("#PersonsIds").val(), 95 IsTheme: Book.GetRadioVal("#IsTheme_1", "#IsTheme_2"), 96 Images: $("#Images").val(), 97 Name: $("#Name").val(), 98 WordsCount: $("#WordsCount").val(), 99 Description: $("#Description").val(), 100 Publisher: $("#Publisher").val(), 101 RelatedPersonCount: "0", 102 RelatedLocationCount: "0", 103 TagIds: JSON.stringify(tagIds), 104 Disabled: true, 105 CreatedTime: Book.GetTime() 106 }; 107 108 Book.SubmitInfo("odata/BooksOData",Book.TypeWay, _param, function () { 109 refreshGrid(Book.gridId); 110 $("#BooksDialog").dialog("close"); 111 }); 112 } 113 }, 114 { 115 id: 'user-cancel', 116 text: '取消', 117 click: function () { 118 $(this).dialog("close"); 119 } 120 121 } 122 ], 123 open: function () { 124 $("#user-ok").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 125 .addClass("btn btn-primary"); 126 127 $("#user-cancel").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 128 .addClass("btn btn-default"); 129 130 $("#user-ok").blur(); 131 $("#user-cancel").blur(); 132 InitializeSiverlight('PortraitSilverLight', 'PortraitId', false); 133 InitializeSiverlight('BackgroundImageSilverLight', 'BackgroundImageId', false); 134 } 135 }); 136 137 138 var imgDialog = $("#uploadImgDialog").dialog({ 139 autoOpen: false, 140 width: 400, 141 height: 200, 142 modal: true, 143 resizable: false, 144 buttons: [ 145 { 146 id: 'img-ok', 147 text: '确定', 148 click: function () { 149 150 var imgId = $('#ImageId').val(); 151 var img = { 152 Id: imgId 153 }; 154 var imgs = JSON.parse($('#Images').val()); 155 if (Global.EditingImgId != emptyGuid) { 156 imgs = editJsonObject(Global.EditingImgId, imgs, img); 157 Global.EditingImgId = emptyGuid; 158 } else { 159 imgs = pushJsonObject(img, imgs); 160 } 161 showImgs('imgBox', imgs); 162 var imgsText = JSON.stringify(imgs); 163 $('#Images').val(imgsText); 164 $(this).dialog("close"); 165 } 166 }, 167 { 168 id: 'img-cancel', 169 text: '取消', 170 click: function () { 171 $(this).dialog("close"); 172 } 173 } 174 ], 175 open: function () { 176 $("#img-ok").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 177 .addClass("btn btn-primary"); 178 179 $("#imgr-cancel").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 180 .addClass("btn btn-default"); 181 182 $("#img-ok").blur(); 183 $("#img-cancel").blur(); 184 //InitializeSiverlight('PortraitSilverLight', 'PortraitId', false); 185 //InitializeSiverlight('BackgroundImageSilverLight', 'BackgroundImageId', false); 186 } 187 }); 188 189 190 var MessageDialog = $("#MessageDialog").dialog({ 191 autoOpen: false, 192 title: '管理后台', 193 width: 400, 194 height: 250, 195 modal: true, 196 resizable: false, 197 buttons: [ 198 { 199 id: 'Message-ok', 200 text: '确定', 201 click: function () { 202 switch (messageType) { 203 case MessageType.DisableConfirm: 204 Book.Disable(Book.BookID, false); 205 break; 206 case MessageType.EnableConfirm: 207 Book.Disable(Book.BookID, true); 208 break; 209 case MessageType.DeleteConfirmLocationsBook: 210 Book.DelRelation(Book.DeleteRows, "odata/BookLocationsOData", Book.DeleteRows.LocationId); 211 break; 212 case MessageType.DeleteConfirmPersonBook: 213 Book.DelRelation(Book.DeleteRows, "odata/BookPersonsOData", Book.DeleteRows.PersonId); 214 break; 215 default: 216 break; 217 } 218 $(this).dialog("close"); 219 } 220 }, 221 { 222 id: 'Message-cancel', 223 text: '取消', 224 click: function () { 225 $(this).dialog("close"); 226 } 227 228 } 229 ], 230 open: function () { 231 $("#Message-ok").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 232 .addClass("btn btn-primary"); 233 234 $("#Message-cancel").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 235 .addClass("btn btn-default"); 236 237 $("#Message-ok").blur(); 238 $("#Message-cancel").blur(); 239 } 240 }); 241 242 var form = $("#userform"); 243 var validator = form.validate({ 244 errorElement: "span", 245 rules: { 246 "UserName": { 247 required: true, 248 maxlength: 20 249 }, 250 "Password": { 251 required: true, 252 maxlength: 20 253 }, 254 "DisplayName": { 255 required: true, 256 maxlength: 20 257 } 258 }, 259 messages: { 260 "UserName": { 261 required: "请输入用户名", 262 maxlength: $.validator.format("最多不能超过 {0} 字.") 263 }, 264 "Password": { 265 required: "请输入密码", 266 maxlength: $.validator.format("最多不能超过 {0} 字.") 267 }, 268 "DisplayName": { 269 required: "请输入显示名称", 270 maxlength: $.validator.format("最多不能超过 {0} 字."), 271 } 272 }, 273 errorClass: "error" 274 }); 275 276 } 277 278 this.BuildUsersGrid = function () { 279 var now = new Date(); 280 Book.gridId = now.getFullYear().toString() + now.getMonth().toString() + now.getDate().toString() + now.getHours().toString() + now.getMinutes().toString() + now.getSeconds().toString() + now.getMilliseconds().toString(); 281 $("#Books").html("<div id='" + Book.gridId + "'></div>"); 282 283 $("#" + Book.gridId).dataMatrix({ 284 oDataUrl: baseServerUrl + "odata/BooksOData", 285 //extraRequestData: { userStaus: userStaus,userGender:userGender }, 286 implementationType: "bootGrid", 287 isRowNumbersVisible: true, 288 properties: [ 289 290 { type: "string", name: "Id", displayName: "Id", isEditable: false, isKey: true, isColumnHidden: true, isSearchable: false, isSortable: false }, 291 { type: "datetime", name: "CreatedTime", displayName: "时间", isSearchable: true, isSortable: false }, 292 { type: "string", name: "AuthorId", displayName: "作者", isSearchable: true, isSortable: true, isColumnHidden: true }, 293 { type: "string", name: "IsTheme", displayName: "主题", isEditable: false, isSortable: false, isColumnHidden: true }, 294 { type: "string", name: "Name", displayName: "书名称", isEditable: true, isSortable: false }, 295 { type: "string", name: "WordsCount", displayName: "字数", isSearchable: true, isSortable: true }, 296 { type: "string", name: "Description", displayName: "描述", isSearchable: true, isSortable: true }, 297 { type: "string", name: "Publisher", displayName: "出版社", isSearchable: true, isSortable: true }, 298 { type: "string", name: "RelatedPersonCount", displayName: "与人关系数", isSearchable: true, isSortable: true, isColumnHidden: true }, 299 { 300 type: "link", name: "link", displayName: "与人关系数", typeOptions: { 301 hrefBuilder: function (row) { 302 var hrefFormat = 'javascript:Book.ShowBookPersonRelation({0});'; 303 //showPersonPersons(row); 304 return hrefFormat.format('"' + row.Id + '"'); 305 }, 306 valueBuilder: function (row) { 307 var valueFormat = "{0}"; 308 return valueFormat.format(row.RelatedPersonCount); 309 }, 310 target: '_blank' 311 } 312 }, 313 { type: "string", name: "RelatedLocationCount", displayName: "与地关系数", isSearchable: true, isSortable: true, isColumnHidden: true }, 314 { 315 type: "link", name: "link", displayName: "与地关系数", typeOptions: { 316 hrefBuilder: function (row) { 317 var hrefFormat = 'javascript:Book.ShowBookLocationRelation({0});'; 318 //showPersonPersons(row); 319 return hrefFormat.format('"' + row.Id + '"'); 320 }, 321 valueBuilder: function (row) { 322 var valueFormat = "{0}"; 323 return valueFormat.format(row.RelatedLocationCount); 324 }, 325 target: '_blank' 326 } 327 }, 328 { type: "enumstring", typeOptions: { "enumValues": { false: "未启用", true: "已启用" } }, name: "Disabled", displayName: "启用状态" }, 329 { type: "action", displayName: "操作", columnWidth: 240, isSortable: false, isSearchable: false }, 330 ], 331 isHeaderBarShow: true, 332 rowCountPerPage: 50, 333 rowCountsPerPage: [50, 100, -1], 334 isRowNumbersVisible: true, 335 isCreateButtonVisible: false, 336 isEditButtonVisible: false, 337 isDeleteButtonVisible: false, 338 defaultSortAscending: false, 339 isMultipleSelection: false, 340 isColumnChooserEnabled: true, 341 defaultSortPropertyName: "CreatedTime", 342 actionButtons: [ 343 { 344 displayName: "编辑", 345 buttonType: DataMatrixRowActionButtonType.Link, 346 buttonClass: "pd-left", 347 onClick: function (button, rowId) { 348 var row = $("#" + Book.gridId).dataMatrix("getRow", rowId); 349 Global.FormMethod = "put"; 350 Global.EditingEntityId = row.Id; 351 Book.EditRow("#BooksDialog",true,row); 352 } 353 }, 354 355 { 356 displayName: "禁用", 357 buttonType: DataMatrixRowActionButtonType.Link, 358 onClick: function (button, rowId) { 359 var row = $("#" + Book.gridId).dataMatrix("getRow", rowId); 360 Book.BookID = rowId; 361 Book.ShowMessage(MessageType.DisableConfirm); 362 } 363 }, 364 { 365 displayName: "启用", 366 buttonType: DataMatrixRowActionButtonType.Link, 367 onClick: function (button, rowId) { 368 var row = $("#" + Book.gridId).dataMatrix("getRow", rowId); 369 Book.BookID = rowId; 370 Book.ShowMessage(MessageType.EnableConfirm); 371 } 372 } 373 ], 374 }); 375 } 376 377 this.InitRelation = function () { 378 379 var PersonPersonsDialog = $("#BooksRelationDialog").dialog({ 380 autoOpen: false, 381 width: 1000, 382 height: 700, 383 modal: true, 384 resizable: false, 385 buttons: [ 386 { 387 id: 'PersonPerson-distribution-cancel', 388 text: '关闭', 389 click: function () { 390 $(this).dialog("close"); 391 } 392 393 } 394 ], 395 open: function () { 396 $("#PersonPerson-distribution-ok").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 397 .addClass("btn btn-primary"); 398 399 $("#PersonPerson-distribution-cancel").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 400 .addClass("btn btn-default"); 401 402 $("#PersonPerson-distribution-ok").blur(); 403 $("#PersonPerson-distribution-cancel").blur(); 404 //document.getElementById("imageValidate").style.display = "none"; 405 } 406 }); 407 408 409 $("#foodItemDialog").dialog({ 410 autoOpen: false, 411 width: 400, 412 height: 400, 413 modal: true, 414 resizable: false, 415 buttons: [ 416 { 417 id: 'user-ok', 418 text: '确定', 419 click: function () { 420 var _url=""; 421 if (Book.FormType == 0) 422 { 423 _url ="odata/BookPersonsOData"; 424 } 425 else 426 { 427 _url = "odata/BookLocationsOData"; 428 } 429 430 var _param = { 431 BookId:$("#btn_create_personPerson").attr("href_personId"), 432 PersonId: $("#persons-select").val(), 433 LocationId:$("#location-select").val(), 434 Type: $("#RelationType").val(), 435 Description: $("#description_foodItem").val(), 436 Disabled: Book.GetRadioVal("#isEnableItem_1", "#isEnableItem_2"), 437 CreatedTime: $("#itemcreatedtime").val(), 438 }; 439 440 Book.SubmitInfo(_url, Book.TypeWay, _param, function () { 441 $("#foodItemDialog").dialog("close"); 442 refreshGrid(Book.gridItemId); 443 refreshGrid(Book.gridId); 444 }); 445 } 446 }, 447 { 448 id: 'user-cancel', 449 text: '取消', 450 click: function () { 451 $(this).dialog("close"); 452 } 453 454 } 455 ], 456 open: function () { 457 $("#itemform tr").show(); 458 if (Book.FormType == 0) { 459 460 $("#ui-id-5").html("与人关系管理"); 461 $("#itemform tr").eq(1).hide(); 462 } 463 else { 464 $("#ui-id-5").html("与地关系管理"); 465 $("#itemform tr").eq(0).hide(); 466 } 467 468 $("#user-ok").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 469 .addClass("btn btn-primary"); 470 471 $("#user-cancel").removeClass("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only") 472 .addClass("btn btn-default"); 473 474 $("#user-ok").blur(); 475 $("#user-cancel").blur(); 476 InitializeSiverlight('PortraitSilverLight', 'PortraitId', false); 477 InitializeSiverlight('BackgroundImageSilverLight', 'BackgroundImageId', false); 478 } 479 }); 480 }; 481 482 this.BindRelationClick = function () { 483 484 //新增用户 485 $("#btn_create_personPerson").click(function () { 486 Book.AddRow("#foodItemDialog",false); 487 }); 488 }; 489 490 this.ShowBookPersonRelation = function (rowId) { 491 Book.FormType = 0; 492 $.ajaxSetup({ async: false }); 493 //Global.FoodTypeID = rowId; 494 $("#btn_create_personPerson").attr("href_personId", rowId); 495 var now = new Date(); 496 Book.gridItemId = "batchOrderGrid" + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds(); 497 $("#BooksRelation").html("<div id='" + Book.gridItemId + "' />"); 498 $("#" + Book.gridItemId).dataMatrix({ 499 oDataUrl: baseServerUrl + "odata/BookPersonDtoOData", 500 extraRequestData: { personId:null , bookId: rowId }, 501 implementationType: "bootGrid", 502 isRowNumbersVisible: true, 503 properties: [ 504 { type: "string", name: "PersonId", displayName: "PersonId", isEditable: false,isColumnHidden: true, isKey: true, isSearchable: false, isSortable: false }, 505 { type: "string", name: "PersonName", displayName: "人物名称", isEditable: false, isSearchable: false, isSortable: false }, 506 { type: "string", name: "Type", displayName: "Type", isEditable: false, isSearchable: false, isSortable: false }, 507 { type: "string", name: "Description", displayName: "描述", columnWidth: 240, isSortable: true }, 508 { type: "datetime", name: "CreatedTime", displayName: "创建时间", isSortable: false, isSearchable: false }, 509 { type: "enum", typeOptions: { "enumValues": { true: "启用", false: "禁用" } }, name: "Disabled", displayName: "状态", isEditable: true, isSortable: false, isSearchable: false }, 510 { type: "action", displayName: "操作", columnWidth: 240, isSortable: false, isSearchable: false }, 511 ], 512 isHeaderBarShow: true, 513 rowCountPerPage: 50, 514 rowCountsPerPage: [50, 100, -1], 515 isRowNumbersVisible: true, 516 isCreateButtonVisible: false, 517 isEditButtonVisible: false, 518 isDeleteButtonVisible: false, 519 defaultSortAscending: true, 520 isMultipleSelection: false, 521 isColumnChooserEnabled: true, 522 defaultSortPropertyName: "Position", 523 actionButtons: [ 524 { 525 displayName: "编辑", 526 buttonClass: "pd-left", 527 buttonType: DataMatrixRowActionButtonType.Link, 528 onClick: function (button, rowId) { 529 530 var row_foodItems = $("#" + Book.gridItemId).dataMatrix("getRow", rowId); 531 Global.FormMethod = "put"; 532 Book.EditRows = row_foodItems; 533 Book.EditRow("#foodItemDialog", false, row_foodItems); 534 } 535 }, 536 { 537 displayName: "删除", 538 buttonType: DataMatrixRowActionButtonType.Link, 539 onClick: function (button, rowId) { 540 var row_foodItems = $("#" + Book.gridItemId).dataMatrix("getRow", rowId); 541 Book.DeleteRows = row_foodItems; 542 Book.ShowMessage(MessageType.DeleteConfirmPersonBook); 543 } 544 } 545 ], 546 }); 547 548 $("#BooksRelationDialog").dialog("open").dialog({ "title": "与人关系数" }); 549 $.ajaxSetup({ async: true, cache: true }); 550 551 552 $.ajaxSetup({ async: true }) 553 for (var i = 0; i < $("#" + Book.gridItemId + "-grid tr").length; i++) { 554 var td = $("td:nth(2)", $("#" + Book.gridItemId + "-grid tr")[i]); 555 td.prop("title", td.text()); 556 } 557 } 558 559 560 this.ShowBookLocationRelation = function (rowId) { 561 Book.FormType = 1; 562 $.ajaxSetup({ async: false }); 563 //Global.FoodTypeID = rowId; 564 $("#btn_create_personPerson").attr("href_personId", rowId); 565 var now = new Date(); 566 Book.gridItemId = "batchOrderGrid" + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds(); 567 $("#BooksRelation").html("<div id='" + Book.gridItemId + "' />"); 568 $("#" + Book.gridItemId).dataMatrix({ 569 oDataUrl: baseServerUrl + "odata/BookLocationDtoOData", 570 extraRequestData: { LocationId:null , bookId: rowId }, 571 implementationType: "bootGrid", 572 isRowNumbersVisible: true, 573 properties: [ 574 { type: "string", name: "LocationId", displayName: "LocationId", isEditable: false, isKey: true, isColumnHidden: true, isSearchable: false, isSortable: false }, 575 { type: "string", name: "LocationName", displayName: "地名称", isEditable: false, isSearchable: false, isSortable: false }, 576 { type: "string", name: "Type", displayName: "Type", isEditable: false, isSearchable: false, isSortable: false }, 577 { type: "string", name: "Description", displayName: "描述", columnWidth: 240, isSortable: true }, 578 { type: "datetime", name: "CreatedTime", displayName: "创建时间", isSortable: false, isSearchable: false }, 579 { type: "enum", typeOptions: { "enumValues": { true: "启用", false: "禁用" } }, name: "Disabled", displayName: "状态", isEditable: true, isSortable: false, isSearchable: false }, 580 { type: "action", displayName: "操作", columnWidth: 240, isSortable: false, isSearchable: false } 581 ], 582 isHeaderBarShow: true, 583 rowCountPerPage: 50, 584 rowCountsPerPage: [50, 100, -1], 585 isRowNumbersVisible: true, 586 isCreateButtonVisible: false, 587 isEditButtonVisible: false, 588 isDeleteButtonVisible: false, 589 defaultSortAscending: true, 590 isMultipleSelection: false, 591 isColumnChooserEnabled: true, 592 defaultSortPropertyName: "Position", 593 actionButtons: [ 594 { 595 displayName: "编辑", 596 buttonClass: "pd-left", 597 buttonType: DataMatrixRowActionButtonType.Link, 598 onClick: function (button, rowId) { 599 600 var row_foodItems = $("#" + Book.gridItemId).dataMatrix("getRow", rowId); 601 Global.FormMethod = "put"; 602 Book.EditRows = row_foodItems; 603 Book.EditRow("#foodItemDialog", false, row_foodItems); 604 } 605 }, 606 { 607 displayName: "删除", 608 buttonType: DataMatrixRowActionButtonType.Link, 609 onClick: function (button, rowId) { 610 var row_foodItems = $("#" + Book.gridItemId).dataMatrix("getRow", rowId); 611 Book.DeleteRows = row_foodItems; 612 Book.ShowMessage(MessageType.DeleteConfirmLocationsBook); 613 } 614 } 615 ], 616 }); 617 618 $("#BooksRelationDialog").dialog("open").dialog({ "title": "与地关系数" }); 619 $.ajaxSetup({ async: true, cache: true }); 620 621 622 $.ajaxSetup({ async: true }) 623 for (var i = 0; i < $("#" + Book.gridItemId + "-grid tr").length; i++) { 624 var td = $("td:nth(2)", $("#" + Book.gridItemId + "-grid tr")[i]); 625 td.prop("title", td.text()); 626 } 627 } 628 629 this.EditRow = function (dialogdiv, bol, row) { 630 Book.TypeWay = "Put"; 631 Book.BookID = row.Id; 632 if (typeof (Book.BookID) == "undefined") 633 { 634 Book.BookID = row.BookId; 635 } 636 637 //关系流程 638 if (!bol) { 639 if (Book.FormType == 0) { 640 Book.FillSelect('persons-select', "odata/PersonsOData", "Get", row.PersonId); 641 } 642 else { 643 Book.FillSelect('location-select', "odata/LocationsOData", "Get", row.LocationId); 644 } 645 $("#itemcreatedtime").val(row.CreatedTime); 646 $("#RelationType").val(row.Type); 647 $("#description_foodItem").val(row.Description); 648 649 $(dialogdiv).dialog("open"); 650 } 651 //主记录流程 652 else { 653 654 var imgs = JSON.parse(row.Images); 655 showImgs('imgBox', imgs); 656 Book.FillSelect("TagIds", "odata/TagsOData", "Get", null); 657 $('#TagIds').multiselect('select', JSON.parse(row.TagIds)); 658 Book.FillSelect("PersonsIds", "odata/PersonsOData", "Get", row.AuthorId); 659 660 $("#Name").val(row.Name); 661 $("#WordsCount").val(row.WordsCount); 662 $("#Publisher").val(row.Publisher); 663 $("#Description").val(row.Description); 664 665 $("#RelatedBookCount").val(row.RelatedBookCount); 666 $("#RelatedLocationCount").val(row.RelatedLocationCount); 667 $("#Disabled").val(row.Disabled); 668 $("#CreatedTime").val(row.CreatedTime); 669 670 Book.SetRadio("#IsTheme_1", "#IsTheme_2", true); 671 672 $(dialogdiv).dialog("open"); 673 } 674 }; 675 676 //添加一行数据,如果是主数据,则bol为true,关系数据则为false 677 this.AddRow = function (dialogdiv, bol) { 678 Book.TypeWay = "Post"; 679 Book.BookID = emptyGuid; 680 if (!bol) { 681 682 if (Book.FormType == 0) { 683 Book.FillSelect('persons-select', "odata/PersonsOData", "Get", null); 684 } 685 else { 686 Book.FillSelect('location-select', "odata/LocationsOData", "Get", null); 687 } 688 } 689 else { 690 Book.FillSelect("TagIds", "odata/TagsOData", "Get", null); 691 Book.FillSelect("PersonsIds", "odata/PersonsOData", "Get", null); 692 693 } 694 Global.FormMethod = "post"; 695 696 $("#RelationType").val(""); 697 $("#description_foodItem").val(""); 698 $("#itemcreatedtime").val(""); 699 $(dialogdiv).dialog("open"); 700 }; 701 702 this.FillSelect = function (domid, InterfaceName, typeWay, objectId) { 703 var personDocument = $("#" + domid); 704 var personsOptions = []; 705 var url = baseServerUrl + InterfaceName; 706 $.ajax({ 707 url: url, 708 type: typeWay, 709 async: false, 710 success: function (data) { 711 var personArray = data.value; 712 for (var i = 0; i < data.value.length; i++) { 713 var option = { 714 label: personArray[i].Name, 715 value: personArray[i].Id 716 } 717 //兼容标签数据 718 if (option.label ==undefined) 719 { 720 option.label = personArray[i].TagName; 721 } 722 723 personsOptions.push(option); 724 } 725 personDocument.multiselect('dataprovider', personsOptions); 726 727 //参数objectId不为空和null,则锁定当前项 728 if (objectId != "" && objectId != null) { 729 personDocument.multiselect('select', objectId); 730 } 731 } 732 }); 733 } 734 735 //提交表单InterfaceName 接口名称,提交方式,参数,回调 736 this.SubmitInfo = function (InterfaceName, typeWay, param, callback) { 737 var form = $("#itemform"); 738 form.submit(function (event) { event.preventDefault(); }); 739 form.submit(); 740 var validator = form.validate(); 741 var _url = typeWay == "Put" ? getRawUrl(InterfaceName) + "(" + Book.BookID + ")" : getRawUrl(InterfaceName); 742 if (validator.numberOfInvalids() <= 0) { 743 $.ajax({ 744 url: _url, 745 data: param, 746 type: typeWay, 747 async: false, 748 success: function (data) { 749 callback && callback(); 750 }, 751 error: function (data) { 752 if (data.status == "409") 753 { 754 alert("您已经添加相同的数据!"); 755 } 756 } 757 }); 758 } 759 }; 760 761 this.Disable=function(id,bol) { 762 var url = getRawUrl("odata/BooksOData(" + id + ")") 763 var _param = { 764 "Disabled": bol 765 } 766 $.ajax({ 767 url: url, 768 data: _param, 769 type: 'PATCH', 770 success: function (data) { 771 refreshGrid(Book.gridId); 772 } 773 }); 774 } 775 776 this.DelRelation = function (_param, interfaceName,id) { 777 var url = getRawUrl(interfaceName + "(" + id + ")"); 778 $.ajax({ 779 url: url, 780 data: _param, 781 type: 'Delete', 782 success: function (data) { 783 refreshGrid(Book.gridItemId); 784 refreshGrid(Book.gridId); 785 } 786 }); 787 }; 788 789 this.ShowMessage = function (msgType) { 790 var message = ""; 791 messageType = msgType; 792 switch (msgType) { 793 case MessageType.DisableConfirm: 794 message = "您确定禁用吗?"; break; 795 case MessageType.EnableConfirm: 796 message = "您确定启用吗?"; break; 797 case MessageType.DeleteConfirmLocationsBook: 798 message = "您确定删除吗?"; break; 799 case MessageType.DeleteConfirmPersonBook: 800 message = "您确定删除吗?"; break; 801 default: 802 message = "无消息提醒"; 803 } 804 $("#message").html(message); 805 $("#MessageDialog").dialog("open"); 806 }; 807 808 this.GetTime = function () { 809 var _date = new Date(); 810 return _date.toLocaleDateString() + " " + _date.getHours() + ":" + _date.getMinutes() + ":" + _date.getSeconds(); 811 } 812 813 //获取Radio选中的值 814 this.GetRadioVal = function (radio1, radio2) { 815 if ($(radio1).get(0).checked) { 816 return true; 817 } 818 else { 819 return false; 820 } 821 } 822 823 //设置Radio 824 this.SetRadio = function (radio1, radio2,bol) { 825 if (bol) { 826 $(radio1).get(0).checked = true; 827 } 828 else { 829 $(radio2).get(0).checked = true; 830 } 831 } 832 833 });