@@ -1,8 +1,12 @@
<div class =" container" >
<div class =" container" ng-controller = " shopProduct " >
<div class =" col-xs-2" >
<% include sidebar .ejs %>
</div >
<div class =" col-xs-10" ng-controller =" shopProduct" >
<div class =" col-xs-10" >
<legend ><%= title%>
<small class =" pull-right text-danger hide" ><i class =" fa fa-info" ></i > <span id =" errorInfo" ></span ></small >
<small class =" pull-right text-success hide" ><i class =" fa fa-info" ></i > <span id =" successInfo" ></span ></small >
</legend >
<div class =" panel panel-info" >
<div class =" panel-body" >
<form class =" form-inline" name =" filterForm" >
@@ -30,7 +34,7 @@
<input type =" text" class =" form-control" name =" endDate" ng-model =" filterData.endDate" style =" width :100px ;" />
</div >
</div >
<button type = " submit " class =" btn btn-default btn-sm" ng-click =" load()" >Go!</button >
<a class =" btn btn-default btn-sm" ng-click =" load()" >Go!</a >
</form >
</div >
</div ><!-- End panel -->
@@ -49,16 +53,24 @@
<th >Name</th >
<th >State</th >
<th >Shop Owner</th >
<th >Contact</th >
<th >Visits</th >
<th >Sale Data</th >
<th >Date</th >
<th >Operation</th >
</tr >
<tr class =" datalist" ng-repeat =" item in data" >
<td ><input type =" checkbox" name =" listItem" class =" mini" value =" " ng-click =" " /></td >
<td ><input type =" checkbox" name =" listItem" class =" mini" value =" {{item._id}}" /></td >
<td ><a >{{item.name}}</a ></td >
<td >{{item.state}}</td >
<td >{{item.shop.username}}</td >
<td >{{item.visits}}</td >
<td >{{item.name}}</td >
<td >{{item.date}}</td >
<td >
<button >Edit</button >
</td >
</tr >
<tr class =" datalist" ng-show =" !data.length" ><td colspan =" 8" class =" text-center" ><h4 >Nothing here.Add product first.</h4 ></td ></tr >
</table >
</div ><!-- /.box-body -->
<div class =" box-footer" >
@@ -70,23 +82,23 @@
</div >
</div ><!-- /.box -->
</div >
<!-- 添加新用户模态窗口 -->
<!-- 模态窗口 -->
<div class =" modal fade" id =" productModal" >
<div class =" modal-dialog" style =" width :1100 px ;" >
<div class =" modal-dialog" style =" width :1000 px ;" >
<div class =" modal-content" >
<div class =" modal-header" >
<button type =" button" class =" close" data-dismiss =" modal" aria-label =" Close" ><span aria-hidden =" true" >× ; </span ></button >
<h4 class =" modal-title" >New Administrator </h4 >
<h4 class =" modal-title" >New Product </h4 >
</div >
<div class =" modal-body" >
<form role =" form" class =" form-horizontal" name =" productForm" ng-submit =" processForm(productForm.$valid)" novalidate >
<div class =" alert alert-danger alert-dismissible hide" role =" alert" >
<div class =" alert alert-danger alert-dismissible text-center hide" role =" alert" >
<button type =" button" class =" close" data-dismiss =" alert" aria-label =" Close" ><span aria-hidden =" true" >× ; </span ></button >
<strong >Error!</strong > <span class =" errorInfo " >Some fields are invalid.</span >
<strong >Error!</strong > <span class =" text " >Some fields are invalid.</span >
</div >
<div class =" form-group" >
<label class =" control-label col-sm-4" >Name</label >
<div class =" col-sm-6 " >
<div class =" col-sm-4 " >
<input type =" text" class =" form-control" name =" name" ng-model =" formData.name" ng-minlength =" 2" ng-maxlength =" 30" required />
<label for =" inputError" class =" control-label text-danger" ng-show =" productForm.name.$invalid && !productForm.name.$pristine" ><i class =" fa fa-times-circle-o" ></i > 2-30 letters</label >
</div >
@@ -95,59 +107,56 @@
<label class =" control-label col-sm-4" >Description</label >
<div class =" col-sm-6" >
<input type =" text" class =" form-control" name =" description" ng-minlength =" 4" ng-maxlength =" 100" ng-model =" formData.description" required />
<label for =" inputError" class =" control-label text-danger" ng-show =" productForm.password .$invalid && !productForm.password .$pristine" ><i class =" fa fa-times-circle-o" ></i >4-100 letters</label >
<label for =" inputError" class =" control-label text-danger" ng-show =" productForm.description .$invalid && !productForm.description .$pristine" ><i class =" fa fa-times-circle-o" ></i >4-100 letters</label >
</div >
</div >
<div class =" form-group" >
<label class =" control-label col-sm-4" >Classify</label >
<div class =" col-sm-6" >
<select class =" form-control input-sm" >
<option value =" " ng-show =" cate_options" >Choose a class</option >
<option value =" " ng-show =" !cate_options" >There's no Classification.</option >
<option value =" opt._id" ng-repeat =" opt in cate_options" >{{opt.name}}</option >
</select >
<div class =" col-sm-4" >
<select class =" form-control input-sm" name =" category_id" ng-model =" formData.category_id" ng-options =" x.me.name for x in cateOptions" ></select >
</div >
</div >
<div class =" form-group" >
<label class =" control-label col-sm-4" >Category</label >
<div class =" col-sm-6" >
<select class =" form-control input-sm" >
<option value =" " >Choose a category</option >
<option value =" opt._id" ng-repeat =" opt in shop_cate_options" >{{opt.name}}</option >
</select >
<div class =" col-sm-4" >
<select class =" form-control input-sm" name =" shop_category_id" ng-model =" formData.shop_category_id" ng-options =" x.me.name for x in shopCateOptions" ></select >
</div >
</div >
<div class =" form-group" >
<label class =" control-label col-sm-4" >Storage</label >
<div class =" col-sm-6 " >
<input type =" text" class =" form-control" name =" storage" ng-model =" formData.storage" ng-pattern =" /^[0 -9][1 -9]{1 ,11}$/" required />
<div class =" col-sm-3 " >
<input type =" text" class =" form-control" name =" storage" ng-model =" formData.storage" ng-pattern =" /^[1 -9][0 -9]{0 ,11}$/" required />
<label for =" inputError" class =" control-label text-danger" ng-show =" productForm.storage.$invalid && !productForm.storage.$pristine" ><i class =" fa fa-times-circle-o" ></i > 1-12 numbers</label >
</div >
</div >
<div class =" form-group" >
<label class =" control-label col-sm-4" >Price</label >
<div class =" col-sm-6 " >
<div class =" col-sm-3 " >
<div class =" input-group" >
<div class =" input-group-addon" >$</div >
<input type =" text" class =" form-control input" name =" startPrice " ng-model =" formData.price" />
<input type =" text" class =" form-control input" name =" price " ng-model =" formData.price" ng-minlength = " 1 " ng-maxlength = " 12 " ng-pattern = " /^[1-9]+[\.]?[0-9]*$/ " required />
</div >
<label for =" inputError" class =" control-label text-danger" ng-show =" productForm.price.$invalid && !productForm.price.$pristine" ><i class =" fa fa-times-circle-o" ></i > 1-12 numbers, point allowed.</label >
</div >
</div >
<div class =" form-group" >
<label class =" control-label col-sm-4" >Content</label >
<div class =" col-sm-6 " >
<div class =" col-sm-7 " >
< textarea id = " editor " name = " editor " placeholder = " product content... " ></ textarea >
</div >
</div >
<div class =" modal-footer" >
<button type =" submit" class =" btn btn-primary" ng-disabled =" productForm.$invalid" >Submit</button >
<button type =" button" class =" btn btn-default" data-dismiss =" modal" >Cancel</button >
</div >
</form >
</div ><!-- /.modal-body -->
</div ><!-- /.modal-content -->
</div ><!-- /.modal-dialog -->
</div ><!-- /.modal -->
</div >
</div ><!-- End container -->
<script src =" /plugins/wysiwyg/js/editor.js" type =" text/javascript" ></script >
<script >
$ (function () {
@@ -160,23 +169,90 @@
});
App .controller (' shopProduct' , function ($scope , $http ) {
' use strict' ;
$scope .filterData = {};
$scope .sortData = {};
url = ' /api/v1/product' ;
$scope .shopInfo = {};
$scope .targetId = ' ' ;
var url = ' /api/v1/product' ,
cateUrl = ' /api/v1/category' ;
// shop info
$http .get (' /api/v1/shop/mine' ).success (function (data ) {
if (typeof data === ' object' ) {
$scope .shopInfo = data;
} else {
showErrorInfo (' Get shop info failed.' );
}
});
initPage ($scope, $http, url, true );
$scope .load = function () {
// product data
loadData ($scope, $http, url);
}
$scope .loadCate = function () {
// category
$http .get (cateUrl).success (function (data ) {
if (data !== ' error' ) {
$scope .cateOptions = data;
$scope .cateOptions .unshift ( { me: { name: ' Other' , _id: ' ' } } );
} else {
showFormErrorInfo (' Get system category failed.' );
}
});
$http .get (cateUrl + ' ?shop_id=' + $scope .shopInfo ._id ).success (function (data ) {
if (data !== ' error' ) {
$scope .shopCateOptions = data;
// for (var i = 0; i < data.length; i++) {
// $scope.shopCateOptions.push({ name: data[i].me.name, value: data[i].me._id });
// }
} else {
showFormErrorInfo (' Get shop category failed.' );
}
});
};
// $scope.load();
$scope .processForm = function (isValid ) {
if (isValid) {
$scope .formData .content = $ .trim ($ (' .wysiwyg-editor' ).html ());
var cid = $scope .formData .category_id ;
// $scope.formData.category_id = cid ? cid.value
console .log ($scope .formData );return ;
var method = ' PUT' ;
if ($scope .targetId ) {
method = ' POST' ;
}
augularHttp ($http, method, url, $scope .formData , function (data ) {
if (data === ' success' ) {
$scope .load ();
}
});
} else {
$ ( " form[name='productForm'] div.alert " ). removeClass ( ' hide ' );
showFormErrorInfo ( ' Some fields are invalid. ' );
return false ;
}
};
$ (" #productModal" ).on (' show.bs.modal' , function (event ) {
$scope .loadCate ();
if ($scope .targetId ) {
} else {
}
}).on (' hidden.bs.modal' , function (event ) {
$scope .formData = {};
$scope .targetId = ' ' ;
});
function showFormErrorInfo (info ) {
$ (" form[name='productForm'] div.alert" ).removeClass (' hide' ).find (' span.text' ).text (info);
}
});
</script >