Skip to content

Commit

Permalink
WA功能:用新的 uploader 替换原有 scene 背景上传
Browse files Browse the repository at this point in the history
  • Loading branch information
amio committed Mar 21, 2014
1 parent 4b2790f commit 5c29c9f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 58 deletions.
4 changes: 2 additions & 2 deletions app/partials/pg-pkgedit.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="tools-title">Background</div>
<div class="tools-background">
<label class="tools-bg-thumb">
<input type="file" ng-file="backgroundImage" ng-file-change="fileChange" style="display:none">
<input type="file" uploader data-handlers="sceneBgUploadHandlers" style="display:none">
<img style="height: 100px" ng-src="{{editStat.selectedScene.background||defaults.sceneBackground}}" />
</label>
<button ng-click="editStat.selectedScene.background=''">Remove</button>
Expand Down Expand Up @@ -155,7 +155,7 @@ <h3>Buttons</h3>
<li>
<label>Icon: </label>
<label>
<input style="display: none" uploader data-handlers="iconUploadHandlers" type="file" />
<input type="file" uploader data-handlers="iconUploadHandlers" style="display: none" />
<img ng-src="{{package.icon ? fileRoot + package.icon : 'http://wxddb1.qa.nt.ctripcorp.com/packages/icon.png'}}" />
</label>
</li>
Expand Down
48 changes: 19 additions & 29 deletions app/scripts/controllers/package-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,43 +83,33 @@ angular.module('toHELL')
editService.selectElement(element);
};

function uploadDataFormater(args){
args.url = GLOBAL.apiHost + 'uploadImage/';
args.transformRequest = formDataObject;
args.data = {
appid: $scope.package.appID,
file: args.data.files[0]
};
return args;
}

$scope.iconUploadHandlers = {
before: function(args){
args.url = GLOBAL.apiHost + 'uploadImage/';
args.transformRequest = formDataObject;
args.data = {
appid: $scope.package.appID,
file: args.data.files[0]
};
return args;
},
before: uploadDataFormater,
after: function(data){
if(data.status === '1'){
$scope.package.icon = data.fileName;
}
}
};

$scope.fileChange = function (files) {
$http({
method: 'POST',
url: GLOBAL.apiHost + 'uploadImage/',
headers: {
'Content-Type': 'multipart/form-data'
},
transformRequest: formDataObject,
data: {
appid: $scope.package.appID,
file: files[0]

$scope.sceneBgUploadHandlers = {
before: uploadDataFormater,
after: function(data){
if(data.status == '1'){
var pkgURI = GLOBAL.pkgHost + $scope.package.appID + '/';
$scope.editStat.selectedScene.background = pkgURI + data.fileName;
}
}).success(function (data) {
var pkgURI = GLOBAL.pkgHost + $scope.package.appID + '/';
$scope.editStat.selectedScene.background = pkgURI + data.fileName;
console.log('suc: ', data);
})
.error(function (err) {
console.log('err: ', err);
});
}
};

/**
Expand Down
28 changes: 1 addition & 27 deletions app/scripts/directives/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,40 +422,14 @@
}
]);

/**
* Directive "ng-file" for uploading
*
* Attributes:
* @Attr ng-file {String} the attr to bind on $scope.
* @Attr ng-file-change {String} the method on $scope to call on change.
*/
module.directive('ngFile', function () {
return {
link: function (scope, el, attrs) {
var args = {
bindAttr: attrs['ngFile'] || 'file',
onChange: attrs['ngFileChange']
};
el.bind('change', function (ev) {
scope[args.bindAttr] = ev.target.files;
scope.$apply();

if (args.onChange) {
scope[args.onChange](ev.target.files);
}
});
}
};
});

module.directive('notify', ['$document', 'notifyService', function ($document, notifyService) {

return {
restrict: 'AE',
templateUrl: 'partials/notify.html',
replace: true,
link: function (scope, element) {
// positionCenter(element);
link: function (scope) {
scope.items = notifyService.getItems();
scope.dismiss = function(item){
notifyService.remove(item);
Expand Down

0 comments on commit 5c29c9f

Please sign in to comment.