Brak opisu

edit.js 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ;
  2. spa_define(function() {
  3. return $.use(["spa","util","form","upload"],function (spa,util,fb,upload) {
  4. return {
  5. modal: function(data) {
  6. var root = spa.findInModal(".sys_user_edit");
  7. var form = fb.build(root.find(".newForm"));
  8. var saveBtn = root.find(".opt-save"),
  9. headArea = root.find(".head-ctn"),
  10. save = function () {
  11. form.doPut("../ajax/sys/user", closeThis, {});
  12. };
  13. root.find(".modal-ctrl .icon-times").on("click", function() {
  14. spa.closeModal();
  15. });
  16. var handler = data.hand;
  17. var closeThis = function() {
  18. spa.closeModal();
  19. if(handler) {
  20. handler();
  21. }
  22. };
  23. form.val(data.data);
  24. upload.build({
  25. render: root.find(".upload-btn"),
  26. accept: "image/gif, image/jpeg",
  27. fail: function(errType, errData) {
  28. /*this ={id,name,size,type,abort=function}*/
  29. util.errMsg(this.name + "上传文件错误:" + errType);
  30. this.ele.remove();
  31. saveBtn.on("click", save);
  32. },
  33. async: false,
  34. maxSize: 1024 * 1024 * 10,
  35. done: function(data) {
  36. /*this ={id,name,size,type,abort=function}*/
  37. this.ele.remove();
  38. headArea.find("img").remove();
  39. $("<img></img>").attr("src", "../data/" + data.uri).appendTo(headArea);
  40. form.val({"head":data.uri});
  41. saveBtn.on("click", save);
  42. },
  43. start: function() {
  44. /*this ={id,name,size,type,abort=function}*/
  45. this.ele = $("<div class='upload-item'><div class='progress'></div><span>" + this.name + "</span><div>");
  46. this.ele.appendTo(headArea);
  47. this.progress = this.ele.find(".progress");
  48. saveBtn.off("click");
  49. },
  50. notity: function(total, loaded) {
  51. /*this ={id,name,size,type,abort=function}*/
  52. var vv = ""+Math.ceil(loaded * 100 / total) + "%;"
  53. this.progress.attr("style", "width:" +vv);
  54. this.progress.text(vv);
  55. },
  56. uri: "../ajax/sys/user/head"
  57. });
  58. saveBtn.on("click", save);
  59. }
  60. };
  61. })
  62. });