ui-jquery.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. define([ 'angular', 'jquery' ], function(angular) {
  2. 'use strict';
  3. angular.module('ui.jquery', []).directive('treePanel', ['$http', '$templateCache', '$parse', function($http, $templateCache, $parse) {
  4. // require(['jquery-ztree']);
  5. return {
  6. require : '?ngModel',
  7. restrict : 'EA',
  8. scope : false,
  9. link : function(scope, element, attrs, ngModel) {
  10. var onSelectionChange = $parse(attrs.onClick),
  11. beforeInit = $parse(attrs.beforeInit),
  12. afterInit = $parse(attrs.afterInit);
  13. var setting = {
  14. callback : {
  15. onClick : function(event, treeId, treeNode, clickFlag) {
  16. onSelectionChange(scope, {$data: treeNode, $event: event});
  17. scope.$apply();// 用到了jquery,需要手动apply
  18. }
  19. }
  20. };
  21. $http.get(attrs.url, {
  22. }).success(function(data) {
  23. beforeInit(scope, {$data: data});
  24. attrs.expandFirst && (data.open = true);
  25. var tree = $.fn.zTree.init(element, setting, data);
  26. ngModel.$setViewValue(tree);
  27. if(attrs.expandFirst) {
  28. var nodes = tree.getNodes();
  29. if (nodes.length > 0) {
  30. tree.selectNode(nodes[0]);
  31. onSelectionChange(scope, {$data: nodes[0]});
  32. }
  33. }
  34. afterInit(scope);
  35. }).error(function(err) {
  36. });
  37. }
  38. };
  39. }]).directive("uploadify", ['$parse', function($parse) {
  40. // require(['jquery-uploadify']);
  41. var basePath = (function() {
  42. var pathName = window.location.pathname.substring(1);
  43. var webName = pathName == '' ? '': pathName.substring(0, pathName.indexOf('/'));
  44. if (webName == "") {
  45. return window.location.protocol + '//' + window.location.host;
  46. } else {
  47. return window.location.protocol + '//' + window.location.host + '/' + webName;
  48. }
  49. })();
  50. return {
  51. require : '?ngModel',
  52. restrict : 'A',
  53. link : function(scope, element, attrs, ngModel) {
  54. var opts = angular.extend({}, scope.$eval(attrs.uploadify));
  55. var onSuccess = $parse(attrs.onSuccess);
  56. var isImage = opts.type == 'image';
  57. element.uploadify({
  58. auto : opts.auto != undefined ? opts.auto : true,
  59. multi : true,
  60. method : 'post',
  61. swf : 'static/misc/uploadify.swf',
  62. uploader : opts.uploader || basePath + (isImage ? '/images' : '/file'),
  63. buttonText : opts.buttonText || (isImage ? '上传图片':'上传附件'),
  64. width : opts.width || 80,
  65. height : opts.height || 30,
  66. fileSizeLimit : isImage ? '3072KB' : '10240KB',// 普通文件10MB,图片文件3MB
  67. fileTypeDesc : '选择文件',
  68. fileTypeExts : opts.fileTypeExts || (isImage ? '*.jpg;*.jpeg;*.png;*.gif;*.bmp' : '*.*'),
  69. cancelImg : 'static/lib/jquery/themes/uploadify/img/uploadify-cancel.png',
  70. onUploadSuccess : function(file, d, response) {
  71. $('#' + file.id).find('.data').html(' 上传完毕');
  72. onSuccess(scope, {$data: angular.fromJson(d)[0], $file: file});
  73. }
  74. });
  75. }
  76. };
  77. }]);
  78. });