angular-file-upload
<div id="page-title">
<h2 class="title-hero" ng-if="!isEdit">
{{'Create Tenant'|translate}}
</h2>
<h2 class="title-hero" ng-if="isEdit">
{{'Edit Tenant'|translate}}
</h2>
</div>
<div class="panel">
<div class="panel-body">
<div class="panel">
<div class="panel-heading">
<h4 class="panel-title">
{{'Basic Info'|translate}}
</h4>
</div>
<div class="panel-body">
<form role="form" name="tenantForm">
<div class="form-group row">
<label class="col-md-3 control-label required">{{"ID" | translate}}</label>
<div class="col-md-6">
<input ng-if="!isEdit" name="id" class="form-control" ng-model="tenant.id" required ng-pattern="/^[A-Za-z0-9]*$/" placeholder="{{'please input tenant id'|translate}}...." />
<span class="error" ng-messages="tenantForm.id.$touched && tenantForm.id.$error">
<span ng-message="required"> {{'tenant id is empty'|translate}}</span>
<span ng-message="pattern">{{'tenant id is invalid'|translate}} </span>
</span>
<input ng-if="isEdit" name="id" readonly class="form-control" ng-model="tenant.id" />
</div>
</div>
<div class="form-group row">
<label class="col-md-3 control-label required">{{"Name" | translate}}</label>
<div class="col-md-6">
<input name="name" class="form-control" maxlength="50" ng-model="tenant.name" required placeholder="{{'please input tenant name'|translate}}...." />
<span class="error" ng-messages="tenantForm.name.$touched && tenantForm.name.$error">
<span ng-message="required"> {{'tenant name is empty'|translate}}</span>
<span ng-message="maxlength"> {{'Name must be no more than 50 characters'|translate}}</span>
</span>
</div>
</div>
<div class="form-group row">
<label class="col-md-3 control-label">{{"Description" | translate}}</label>
<div class="col-md-6">
<input name="description" class="form-control" maxlength="500" ng-model="tenant.description" placeholder="{{'please input tenant description'|translate}}...." />
</div>
</div>
<div class="form-group row">
<label class="col-md-3 control-label">{{"Description" | translate}}</label>
<div class="col-md-6">
<div style="display: flex; align-items: flex-end">
<div class="container-flex">
<div class="flex-column">
<input class="filename form-control" type="text" readonly="readonly" ng-model="selectedFile.file.name">
</div>
<div style="margin-left: 5px;width: 60px;">
<label class="btn btn-default">
<input id="logoInput" type="file" nv-file-select uploader="uploader" accept="image/*" style="visibility: collapse;height: 0px;" multiple/>
浏览
</label>
</div>
<div style="margin-left: 5px;width: 60px;" ng-if="selectedFile">
<label class="btn btn-default">
<span ng-click="removeSelectedFile()">{{'CANCEL' | translate}}</span>
</label>
</div>
</div>
</div>
<div>
<img id="img_review" ng-src="{{tenant.logo | logoFilter}}" alt="{{'Invalid icon, please upload an alternative image'|translate}}" style="height:100px" ng-if="tenant.logo && uploader.queue.length === 0" />
<div ng-thumb file="selectedFile" width="128" height="128" ng-if="selectedFile"></div>
</div>
</div>
</div>
<!--<div class="form-group row">-->
<!--<label class="col-md-3 control-label">{{"Description" | translate}}</label>-->
<!--<div class="col-md-6" style="display: flex; align-items: flex-end">-->
<!--<img id="img_review" ng-src="{{tenant.logo | logoFilter}}" alt="{{'Invalid icon, please upload an alternative image'|translate}}" style="height:100px" ng-if="tenant.logo && uploader.queue.length === 0" />-->
<!--<div ng-thumb file="selectedFile" width="128" height="128" ng-if="selectedFile"></div>-->
<!--<input class="control-label" id="logoInput" type="file" nv-file-select uploader="uploader" accept="image/*" />-->
<!--<a ng-click="removeSelectedFile()" ng-if="selectedFile">{{'CANCEL' | translate}}</a>-->
<!--</div>-->
<!--</div>--> <!--<div class="form-group row">-->
<!--<label class="col-md-3 control-label">{{"Description" | translate}}</label>-->
<!--<div class="col-md-6" style="display: flex; align-items: flex-end">-->
<!--<div class="container-flex">-->
<!--<div class="flex-column">-->
<!--<input class="filename form-control" type="text" readonly="readonly" data-ng-model="selectedFile.file.name">-->
<!--</div>-->
<!--<div style="margin-left: 5px;width: 60px;">-->
<!--<div ng-thumb file="selectedFile" width="128" height="128" ng-if="selectedFile"></div>-->
<!--<label class="btn btn-default">-->
<!--<input id="thumbnailInput" type="file" nv-file-select uploader="uploader" accept="image/*" style="visibility: collapse;height: 0px;">-->
<!--浏览-->
<!--</label>-->
<!--<a ng-click="removeSelectedFile()" ng-if="selectedFile">{{'CANCEL' | translate}}</a>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<div class="form-group row">
<div class="col-md-offset-3 col-md-6">
<p class="help-block" style="font-size: 12px;">{{'Image in scale 200 * 54 is best' | translate}}</p>
</div>
</div>
</form>
</div>
</div>
<div class="pull-right">
<button type="button" class="btn btn-primary" ng-if="(isEdit && tenantPermissionUpdate) || (!isEdit && tenantPermissionCreate)" ng-click="submit(tenant)" ng-disabled="tenantForm.$invalid">{{'Save'|translate}}
</button>
<button type="button" class="btn btn-link" ng-click="back()">{{'Back'|translate}}</button>
</div>
</div>
</div>
/* Copyright 2016 Qianyun, Inc. All rights reserved. -- Qianyun Confidential */
/*
*
*/ 'use strict'; angular.module('yacmpApp').controller('TenantEditController', ['$scope', '$window', 'DataService', 'UtilService',
'$uibModal', '$stateParams', '$q', '$timeout', '$location', '$translate', '$filter', 'permissionService', 'commonService', 'FileUploader', function ($scope, $window, DataService, UtilService, $uibModal, $stateParams, $q, $timeout, $location, $translate,
$filter, permissionService, commonService, FileUploader) {
$scope.table_columns_user = ["User Id", "Name", "Email", "Role"]; $scope.isEdit = false;
$scope.tenant = {}; var uploader = $scope.uploader = new FileUploader({
url: UtilService.getBaseUrl() + "/icon/upload",
queueLimit: 1
}); uploader.filters.push({
name: 'imageFilter',
fn: function(item, options) {
var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
}
}); $scope.removeSelectedFile = function(item) {
$scope.selectedFile = null;
$scope.uploader.clearQueue();
}; uploader.onAfterAddingFile = function(item) {
$scope.selectedFile = item;
$scope.$digest();
}; uploader.onWhenAddingFileFailed = function(item, filter, options) {
if (filter.name === "queueLimit") {
uploader.clearQueue(); // NOTE: the angular-file-upload has one trick bug, the item here is now is FileLikeObject but
// not File, so use input element here as a workaround.
var files = $("#logoInput")[0].files;
if (files) {
uploader.addToQueue(files[0], filter, options);
}
}
}; var id = $stateParams.id; if ($stateParams.id) {
$scope.isEdit = true;
DataService.get(CONSTANTS.SERVICE_TENANT_MGMT.PATH + "/" + id + "/with-users").success(function (tenant, status) {
$scope.tenant = tenant;
var requestParam = {};
requestParam.hierarchy = $scope.hierarchy;
requestParam.hierarchyInstanceId = $stateParams.id; }).error(function (data, status, headers, config) {
UtilService.alert($scope,"Couldn't load the tenant, error#",data);
});
} function postTenant(tenant) {
if ($scope.isEdit) {
//update tenant
DataService.put(CONSTANTS.SERVICE_TENANT_MGMT.PATH + "/" + tenant.id, tenant)
.then(function successCallback() {
UtilService.showMessage('Tenant saved', function () {
$location.path('/main/admin/tenant');
}, "SUCCESS");
}, function errorCallback(data) {
UtilService.alert($scope, "Couldn't edit tenant, error#", data);
});
} else {
//create a new tenant
DataService.post(CONSTANTS.SERVICE_TENANT_MGMT.PATH, tenant)
.then(function successCallback() {
UtilService.showMessage('Tenant created', function () {
$location.path('/main/admin/tenant');
}, "SUCCESS");
}, function errorCallback(data) {
UtilService.alert($scope,"Couldn't create tenant, error#",data);
});
}
} $scope.submit = function (tenant) {
if (uploader.queue.length > 0) {
uploader.uploadAll();
uploader.onCompleteItem = function(fileItem, response, status, headers) {
console.info('onCompleteItem, response:', response);
tenant.logo = response;
postTenant(tenant);
};
} else {
postTenant(tenant);
} }; $scope.back = function() {
$location.path('/main/admin/tenant');
}; permissionService.tenantPermission.update.then(
function(permission) {
$scope.tenantPermissionUpdate = permission;
}, function(reject) {
$scope.tenantPermissionUpdate = false;
}
); permissionService.tenantPermission.create.then(
function(permission) {
$scope.tenantPermissionCreate = permission;
}, function(reject) {
$scope.tenantPermissionCreate = false;
}
);
}
]
);
angular-file-upload的更多相关文章
- angularjs file upload插件使用总结
之前由于项目需要,决定使用angularjs做前端开发,在前两个项目中都有文件上传的功能,因为是刚接触angularjs,所以对一些模块和模块间的依赖不是很了解.都是由其他大神搭好框架,我只做些简单的 ...
- Angular2 File Upload
Angular2 File Upload Install Install the components npm install ng2-file-upload --save github: https ...
- [AngularFire] Angular File Uploads to Firebase Storage with Angular control value accessor
The upload class will be used in the service layer. Notice it has a constructor for file attribute, ...
- jQuery File Upload 单页面多实例的实现
jQuery File Upload 的 GitHub 地址:https://github.com/blueimp/jQuery-File-Upload 插件描述:jQuery File Upload ...
- jQuery File Upload done函数没有返回
最近在使用jQuery File Upload 上传图片时发现一个问题,发现done函数没有callback,经过一番折腾,找到问题原因,是由于dataType: ‘json’造成的,改为autoUp ...
- kindeditor多图片上传找不到action原来是private File upload成员变量惹得祸
kindeditor多图片上传找不到action原来是private File upload成员变量惹得祸
- 【转发】Html5 File Upload with Progress
Html5 File Upload with Progress Posted by Shiv Kumar on 25th September, 2010Senior Sof ...
- 用jQuery File Upload做的上传控件demo,支持同页面多个上传按钮
需求 有这么一个需求,一个form有多个文件要上传,但又不是传统的图片批量上传那种,是类似下图这种需求,一开始是用的swfupload做的上传,但是问题是如果有多个按钮的话,就要写很多重复的代码,于为 ...
- jquery file upload 文件上传插件
1. jquery file upload 下载 jquery file upload Demo 地址:https://blueimp.github.io/jQuery-File-Upload/ jq ...
- jQuery File Upload跨域上传
最近在做一个一手粮互联网项目,方案为前后端分离,自己负责前端框架,采用了Requirejs+avalonjs+jquery三个框架完成. 前后端通过跨域实现接口调用,中间也发现了不少问题,尤其是在富文 ...
随机推荐
- BI开发之——Mdx基础语法(转至指尖流淌)
Mdx为MultiDimensional Expressions的缩写,多维表达式,是标准的OLAP查询语言.在多数OLAPServer都提供Mdx支持,如Microsoft Sql Server ...
- 【转】【iOS测试系列】常用测试小插件的使用
背景介绍 由于iOS系统的限制,在非越狱的自动化测试中无法实现一些常用的功能,比如不同应用之间来回切换.模拟全局的点击事件等等.但是在越狱的环境下,这些限制就不存在了,我们可以利用各种小插件来实现我们 ...
- Hive三种不同的数据导出的方式
转自:http://blog.chinaunix.net/uid-27177626-id-4653808.html Hive三种不同的数据导出的方式,根据导出的地方不一样,将这些方法分为三类:(1)导 ...
- 那么类 Man 可以从类 Human 派生,类 Boy 可以从类 Man 派生
若在逻辑上 B 是 A 的“一种”(a kind of ),则允许 B 继承 A 的功 能和属性. 例如男人(Man)是人(Human)的一种,男孩(Boy)是男人的一种. 那么类 Man 可以从类 ...
- 【POJ】1523 SPF(割点)
http://poj.org/problem?id=1523 太弱... too weak.. 割点我都还要看书和看题解来写..果然是写不出么.. 割点就那样求,然后分量直接这个节点有多少子树就有子树 ...
- JAVA基础之訪问控制权限(封装)
包:库单元 1.当编写一个Java源码文件时.此文件通常被称为编译单元(有时也被称为转译单元). 2.每一个编译单元都必须有一个后缀名.java,而在编译单元内则能够有一个public类,该类名称必须 ...
- Android中BroadcastReceiver组件具体解释
Android系统的4个组件最终还剩一种组件了BroadcastReceiver,这个组件是全局监听器,能够监听系统全局的广播消息,能够方便的实现系统中不同组件之间的通信 BroadcastRecei ...
- hdu 1026:Ignatius and the Princess I(优先队列 + bfs广搜。ps:广搜AC,深搜超时,求助攻!)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- C#中动态调用DLL动态链接库
其中要使用两个未公开的Win32 API函数来存取控制台窗口,这就需要使用动态调用的方法,动态调用中使用的Windows API函数主要有三个,即:Loadlibrary,GetProcAddress ...
- Codeforces Round #296 (Div. 2) B. Error Correct System
B. Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input stan ...