修改了一下添加书签的一些限制条件

This commit is contained in:
luchenqun 2016-10-28 17:45:08 +08:00
parent 1f2a3a13c6
commit 296b2fb6aa
3 changed files with 42 additions and 20 deletions

View File

@ -1,11 +1,19 @@
app.controller('editCtr', ['$scope', '$state', 'bookmarkService', 'pubSubService', function($scope, $state, bookmarkService, pubSubService) { app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'pubSubService', function($scope, $state, $timeout, bookmarkService, pubSubService) {
console.log("Hello , I enter editCtr..."); console.log("Hello , I enter editCtr...");
init(); init();
semanticInit(); semanticInit();
$scope.$watch('url', function(newValue, oldValue, scope) {
$scope.urlError = $scope.url == '';
});
$scope.$watch('title', function(newValue, oldValue, scope) {
$scope.titleError = $scope.title == '';
});
$scope.addTags = function() { $scope.addTags = function() {
console.log('Hello , you have click add tag btn......'); console.log('Hello , you have click add tag btn......');
$scope.newTags = $scope.newTags.replace("", ","); $scope.newTags = $scope.newTags.replace(//g, ",").replace(/,+/g, ","); // 先将中文逗号替换成英文逗号,然后将多个英文逗号换成一个英文逗号
var tags = $scope.newTags.split(","); var tags = $scope.newTags.split(",");
var params = []; var params = [];
tags.forEach(function(tag) { tags.forEach(function(tag) {
@ -15,10 +23,10 @@ app.controller('editCtr', ['$scope', '$state', 'bookmarkService', 'pubSubService
for (var i = 0; i < $scope.tags.length; i++) { for (var i = 0; i < $scope.tags.length; i++) {
if ($scope.tags[i].name === tag) { if ($scope.tags[i].name === tag) {
find = true; find = true;
$('.ui.fluid.search.dropdown').dropdown('set selected', $scope.tags[i].id); $('.ui.fluid.search.dropdown').dropdown('set selected', $scope.tags[i].id); // 在标签上已有的直接加入标签
} }
}; };
if (!find) { if (!find && tag !== '') {
params.push(tag); params.push(tag);
} }
}); });
@ -33,6 +41,9 @@ app.controller('editCtr', ['$scope', '$state', 'bookmarkService', 'pubSubService
console.log('Hello , you have click ok btn......'); console.log('Hello , you have click ok btn......');
var selectedTags = $('.ui.modal.js-add-bookmark .ui.dropdown').dropdown('get value'); var selectedTags = $('.ui.modal.js-add-bookmark .ui.dropdown').dropdown('get value');
console.log($scope.url, $scope.title, $scope.description, $scope.public, selectedTags); console.log($scope.url, $scope.title, $scope.description, $scope.public, selectedTags);
$scope.urlError = $scope.url == '';
$scope.titleError = $scope.title == '';
$scope.tagsError = (selectedTags.length == 0 || selectedTags.length > 3);
bookmarkService.addBookmark({ bookmarkService.addBookmark({
a: 'Hello i love this world' a: 'Hello i love this world'
@ -76,6 +87,12 @@ app.controller('editCtr', ['$scope', '$state', 'bookmarkService', 'pubSubService
$('.ui.dropdown').dropdown({ $('.ui.dropdown').dropdown({
forceSelection: false, forceSelection: false,
maxSelections: 3, maxSelections: 3,
onChange: function(value, text, $choice) {
var selectedTags = $('.ui.modal.js-add-bookmark .ui.dropdown').dropdown('get value');
$timeout(function() {
$scope.tagsError = (selectedTags.length == 0 || selectedTags.length > 3);
});
}
}); });
}, 1000); }, 1000);
} }
@ -86,6 +103,11 @@ app.controller('editCtr', ['$scope', '$state', 'bookmarkService', 'pubSubService
$scope.description = ''; $scope.description = '';
$scope.newTags = ''; $scope.newTags = '';
$scope.tags = []; // tag = {id:xxx, name:'yyy'} $scope.tags = []; // tag = {id:xxx, name:'yyy'}
$scope.urlError = false;
$scope.titleError = false;
$scope.tagsError = false;
$scope.public = '1'; $scope.public = '1';
} }
}]); }]);

View File

@ -5,20 +5,20 @@
</div> </div>
<div class="content"> <div class="content">
<div class="ui form"> <div class="ui form">
<div class="required field"> <div class="required field" ng-class="{error:urlError}">
<label>书签链接</label> <label>书签链接</label>
<input type="text" placeholder="" ng-model="url"> <input type="text" placeholder="" ng-model="url">
</div> </div>
<div class="required field"> <div class="required field" ng-class="{error:titleError}">
<label>书签标题</label> <label>书签标题</label>
<input type="text" placeholder="" ng-model="title"> <input type="text" placeholder="" ng-model="title">
</div> </div>
<div class="required field"> <div class="required field">
<label>书签分类</label> <label>书签分类</label>
<div class="fields"> <div class="fields">
<div class="eight wide field"> <div class="eight wide field" ng-class="{error:tagsError }">
<select class="ui fluid search dropdown js-tags" multiple="" ng-class="{loading: loadTags }"> <select class="ui fluid search dropdown js-tags" multiple="">
<option value="">选择已有分类,可以使用搜索功能</option> <option value="">选择已有分类,可以搜索已有标签,最多选择三个</option>
<option value="{{ tag.id }}" ng-repeat="tag in tags">{{ tag.name }}</option> <option value="{{ tag.id }}" ng-repeat="tag in tags">{{ tag.name }}</option>
</select> </select>
</div> </div>

View File

@ -1,21 +1,21 @@
var api = require('express').Router(); var api = require('express').Router();
var mysql = require('mysql'); var mysql = require('mysql');
// var client = mysql.createConnection({
// host: '172.24.13.5',
// user: 'root',
// password: 'root123',
// database: 'mybookmarks',
// multipleStatements: true,
// port: 3306
// });
var client = mysql.createConnection({ var client = mysql.createConnection({
host: '127.0.0.1', host: '172.24.13.5',
user: 'lcq', user: 'root',
password: '123456', password: 'root123',
database: 'mybookmarks', database: 'mybookmarks',
multipleStatements: true, multipleStatements: true,
port: 3306 port: 3306
}); });
// var client = mysql.createConnection({
// host: '127.0.0.1',
// user: 'lcq',
// password: '123456',
// database: 'mybookmarks',
// multipleStatements: true,
// port: 3306
// });
client.connect(); client.connect();
api.get('/bookmarks', function(req, res) { api.get('/bookmarks', function(req, res) {