Няма описание

new.js 1.9KB

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