landers.angular
Version:
landers.angular
77 lines (75 loc) • 4.45 kB
JavaScript
;angular.module('Landers.angular')
.directive('landersAttachment', ['$compile', 'Flat', 'Dialog', 'List', function($compile, Flat, Dialog, List) {
return {
restrict : 'A',
link : function($scope, $element, $attrs){
var model_key = $attrs['attachModel'];
var view_key = $attrs['attachView'];
var html = '';
html += '<div class="relative">';
html += ' <a ng-click="landersAttachmentAdd($event)" class="btn btn-sm btn-primary absolute right-top"><i class="glyphicon glyphicon-plus"></i></a>';
html += '</div>';
html += '<input ng-model="' + model_key + '" type="hidden"/>';
html += '<ul class="hlist list">';
html += ' <li ng-repeat="item in ' + view_key + '" class="mr20 list-item">';
html += ' <a href="{{item.url}}" target="_blank">{{item.title}}</a>';
html += ' <a ng-click="landersAttachmentRemove($event)" class="ml5 btn btn-warning btn-xs"><i class="glyphicon glyphicon-minus"></i></a>';
html += ' </li>';
html += '</ul>';
var el = $compile(html)($scope);
$element.css({height:'100%'}).append(el);
// angular_scope_apply($scope);
$element.find('.list').css({'margin-right':$element.find('.btn').width() + 20 })
var lister = List.make($scope, view_key).data([]);
$scope.$watch(model_key, function(model){
if (model) lister.data(model);
});
var html = '';
html += '<form class="form-horizontal">';
html += '<input type="hidden" id="url" ng-model="$runtime.attachment.url"/>';
html += '<table cellpadding="0" cellspacing="0" border="0" class="stereo form-table" style="width:520px;">';
html += ' <tr>';
html += ' <td><label class="control-label">标题</label></td>';
html += ' <td><div class="control-input"><input type="text" class="form-control" ng-model="$runtime.attachment.title"/></div></td>';
html += ' </tr>';
html += ' <tr height="192">';
html += ' <td><label class="control-label">上传</label></td>';
html += ' <td><div class="control-input">';
html += ' <div landers-upload class="upload text-center fl" rel="url" uploadid="7b2aa8e6ba1d06fae48d72ae28dc7469" tipid="upload_attachment_tip" pvw="180" pvh="180"></div>';
html += ' <ul id="upload_attachment_tip" class="fl lh22"></ul>';
html += ' </div></td>';
html += ' </tr>';
html += '</table>';
html += '</form>';
angular.extend($scope, {
landersAttachmentAdd : function(){
Flat.set($scope, '$runtime.attachment', {});
setTimeout(function(){
Dialog.show($scope, {
title : '新增附件',
content : html,
top : '30%',
width : 350,
lock : true,
fixed : true,
effect : 'vmove2',
onload : function(){
},
yes : function(){
var attach = Flat.get($scope, '$runtime.attachment');
lister.append(angular.extend({}, attach));
Flat.set($scope, model_key, angular.toJson(lister.data()));
},
no : true
});
}, 200);
},
landersAttachmentRemove : function($event){
if (!confirm('确定要删除此附件?')) return;
lister.item.remove($event);
Flat.set($scope, model_key, angular.toJson(lister.data()));
}
})
}
}
}]);