Commit f98e8577 authored by Evren Kutar's avatar Evren Kutar

date field custom validation + listnode fix

parent f13aa51b
......@@ -3,6 +3,34 @@
<div class="buttons-on-top-modal"></div>
<hr>
<form name="linkedModelForm" sf-schema="schema" sf-form="form" sf-model="model" modal-form-locator></form>
<div ng-repeat="node in Node">
<h3>{{ node.title }}
<span ng-if="node.lengthModels < 1">
<a href="javascript:void(0);" modal-for-nodes="{{node.schema.model_name}},Node">
<i class="fa fa-plus-circle fa-fw"></i>
</a>
</span>
</h3>
<div class="node-table">
<ng-include src="'shared/templates/nodeTable.html'"></ng-include>
</div>
<hr>
</div>
<div ng-repeat="node in ListNode">
<h3>{{ node.title }}
<span>
<a href="javascript:void(0);" modal-for-nodes="{{node.schema.model_name}},ListNode,add">
<i class="fa fa-plus-circle fa-fw"></i>
</a>
</span>
</h3>
<div class="list-node-table">
<ng-include src="'shared/templates/nodeTable.html'"></ng-include>
</div>
<hr>
</div>
<hr>
<div class="buttons-on-bottom-modal"></div>
</div>
......
<div class="tablescroll">
{{node.model}}
<!--<table class="table table-bordered" style="background-color:#fff;">-->
<!--<thead>-->
<!--<tr ng-if="node.schema.formType=='Node'">-->
<!--&lt;!&ndash;<th colspan="2">&ndash;&gt;-->
<!--&lt;!&ndash;<label>&ndash;&gt;-->
<!--&lt;!&ndash;<input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;">&ndash;&gt;-->
<!--&lt;!&ndash;Hepsini Seç&ndash;&gt;-->
<!--&lt;!&ndash;</label>&ndash;&gt;-->
<!--&lt;!&ndash;</th>&ndash;&gt;-->
<!--<th ng-repeat="(key,value) in node.model">{{ key }}</th>-->
<!--<th>İşlem</th>-->
<!--</tr>-->
<!--<tr ng-if="node.schema.formType=='ListNode'">-->
<table class="table table-bordered" style="background-color:#fff;">
<thead>
<tr ng-if="node.schema.formType=='Node'">
<!--<th colspan="2">-->
<!--<label>-->
<!--<input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;">-->
<!--Hepsini Seç-->
<!--</label>-->
<!--</th>-->
<!--<th ng-repeat="(key,value) in node.model[0]">{{ key }}</th>-->
<!--<th>İşlem</th>-->
<!--</tr>-->
<!--</thead>-->
<!--<tbody ng-class="{hidden: node.lengthModels < 1}">-->
<th ng-repeat="(key,value) in node.model track by $index">{{ key }}</th>
<th>İşlem</th>
</tr>
<tr ng-if="node.schema.formType=='ListNode'">
<th colspan="2">
<label>
<input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;">
Hepsini Seç
</label>
</th>
<th ng-repeat="(key,value) in node.model track by $index">{{ key }}</th>
<th>İşlem</th>
</tr>
</thead>
<tbody ng-class="{hidden: node.lengthModels < 1}">
<!--<tr ng-if="node.schema.formType=='Node'">-->
<!--&lt;!&ndash;<td width="60">&ndash;&gt;-->
<!--&lt;!&ndash;<label>&ndash;&gt;-->
<!--&lt;!&ndash;<input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;">&ndash;&gt;-->
<!--&lt;!&ndash;</label>&ndash;&gt;-->
<!--&lt;!&ndash;</td>&ndash;&gt;-->
<!--&lt;!&ndash;<th scope="row" style="text-align:center">1</th>&ndash;&gt;-->
<!--<td ng-repeat="value in node.model">{{ value }}</td>-->
<!--<td>-->
<!--<button modal-for-nodes="{{node.schema.model_name}},{{node.schema.formType}},edit">Düzenle</button><br>-->
<!--<button>Sil</button>-->
<!--</td>-->
<!--</tr>-->
<!--<tr ng-repeat="listnodemodel in node.model" ng-if="node.schema.formType=='ListNode'">-->
<tr ng-if="node.schema.formType=='Node'">
<!--<td width="60">-->
<!--<label>-->
<!--<input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;">-->
<!--</label>-->
<!--</td>-->
<!--<th scope="row" style="text-align:center">{{$index+1}}</th>-->
<!--<td ng-repeat="(k, v) in listnodemodel">{{ v }}</td>-->
<!--<td>-->
<!--<button modal-for-nodes="{{node.schema.model_name}},{{node.schema.formType}},edit,{{$index}}">Düzenle</button><br>-->
<!--<button>Sil</button>-->
<!--</td>-->
<!--</tr>-->
<!--<th scope="row" style="text-align:center">1</th>-->
<td ng-repeat="value in node.model track by $index">{{ value }}</td>
<td>
<button modal-for-nodes="{{node.schema.model_name}},{{node.schema.formType}},edit">Düzenle</button><br>
<button>Sil</button>
</td>
</tr>
<tr ng-repeat="listnodemodel in node.items track by $index" ng-if="node.schema.formType=='ListNode'">
<td width="60">
<label>
<input type="checkbox" style="zoom:1.5; margin:5px 0 0 8px;">
</label>
</td>
<th scope="row" style="text-align:center">{{$index+1}}</th>
<td ng-repeat="(k, v) in listnodemodel track by $index">{{ v }}</td>
<td>
<button modal-for-nodes="{{node.schema.model_name}},{{node.schema.formType}},edit,{{$index}}">Düzenle</button><br>
<button>Sil</button>
</td>
</tr>
<!--</tbody>-->
<!--</table>-->
</tbody>
</table>
</div>
\ No newline at end of file
......@@ -135,7 +135,11 @@ angular.module('formService', ['ui.bootstrap'])
if (v.type === 'submit' || v.type === 'button') {
var buttonPositions = scope.modalElements ? scope.modalElements.buttonPositions : {bottom: 'move-to-bottom', top: 'move-to-top', none: ''};
var buttonPositions = scope.modalElements ? scope.modalElements.buttonPositions : {
bottom: 'move-to-bottom',
top: 'move-to-top',
none: ''
};
var workOnForm = scope.modalElements ? scope.modalElements.workOnForm : 'formgenerated';
var workOnDiv = scope.modalElements ? scope.modalElements.workOnDiv : '';
var buttonClass = (buttonPositions[v.position] || buttonPositions.bottom);
......@@ -173,7 +177,7 @@ angular.module('formService', ['ui.bootstrap'])
};
// replace buttons according to their position values
$timeout(function () {
var selectorBottom = '.buttons-on-bottom'+workOnDiv;
var selectorBottom = '.buttons-on-bottom' + workOnDiv;
//var selectorTop = '.buttons-on-top'+workOnDiv;
var buttonsToBottom = angular.element(document.querySelector('.' + buttonClass));
......@@ -191,6 +195,25 @@ angular.module('formService', ['ui.bootstrap'])
// check if type is date and if type date found change it to string
if (v.type === 'date') {
scope.form[scope.form.indexOf(k)] = {
key: k, name: k,
validationMessage: {
'dateNotValid': "Girdiğiniz tarih geçerli değildir. <i>orn: '01.01.2015'<i/>"
},
$asyncValidators: {
'dateNotValid': function(value) {
var deferred = $q.defer();
$timeout(function(){
if (isNaN(Date.parse(value)) || value.split('.').length !== 3) {
deferred.reject();
} else {
deferred.resolve();
}
}, 500);
return deferred.promise;
}
}
};
v.type = 'string';
scope.model[k] = generator.dateformatter(scope.model[k]);
......@@ -232,7 +255,7 @@ angular.module('formService', ['ui.bootstrap'])
var modelScope = {"url": v.wf, "form_params": {model: v.model_name, cmd: v.list_cmd}};
//scope.$on('refreshTitleMap', function (event, data) {
// todo: write a function to refresh titleMap after new item add to linkedModel
// todo: write a function to refresh titleMap after new item add to linkedModel
//});
scope.generateTitleMap = function (modelScope) {
......@@ -289,7 +312,10 @@ angular.module('formService', ['ui.bootstrap'])
if ((v.type === 'ListNode' || v.type === 'Node') && v.widget === 'filter_interface') {
var formitem = scope.form[scope.form.indexOf(k)];
var modelScope = {"url": v.wf || scope.wf, "form_params": {model: v.model_name || v.schema[0].model_name, cmd: v.list_cmd || 'select_list'}};
var modelScope = {
"url": v.wf || scope.wf,
"form_params": {model: v.model_name || v.schema[0].model_name, cmd: v.list_cmd || 'select_list'}
};
scope.generateTitleMap = function (modelScope) {
generator.get_list(modelScope).then(function (res) {
......@@ -360,7 +386,7 @@ angular.module('formService', ['ui.bootstrap'])
var dataValues = [];
angular.forEach(data, function (value, key) {
var dataKey = {};
dataKey[v.schema[0].name]=value.value;
dataKey[v.schema[0].name] = value.value;
dataValues.push(dataKey);
});
return dataValues;
......@@ -390,26 +416,26 @@ angular.module('formService', ['ui.bootstrap'])
url: scope.url
});
//if (scope.model[k] === null) {
// scope[v.type][k].model = v.type === 'Node' ? {} : [];
//} else {
// scope[v.type][k].model = scope.model[k];
//}
scope[v.type][k].model = angular.copy(scope.model[k]) || {};
if (v.type === 'ListNode') {scope[v.type][k].items = [];}
if (v.type === 'ListNode') {
scope[v.type][k].items = [];
}
angular.forEach(v.schema, function (item) {
scope[v.type][k].schema.properties[item.name] = item;
scope[v.type][k].schema.properties[item.name] = angular.copy(item);
// prepare required fields
if (item.required === true && item.name !== 'idx') {
scope[v.type][k].schema.required.push(item.name);
scope[v.type][k].schema.required.push(angular.copy(item.name));
}
// idx field must be hidden
if (item.name === 'idx') {
scope[v.type][k].form.push({type: 'string', key: item.name, htmlClass: 'hidden'});
scope[v.type][k].form.push({
type: 'string',
key: angular.copy(item.name),
htmlClass: 'hidden'
});
} else {
scope[v.type][k].form.push(item.name);
}
......@@ -512,6 +538,10 @@ angular.module('formService', ['ui.bootstrap'])
var re = /^([1-9]{1}[0-9]{9}[0,2,4,6,8]{1})$/i;
return re.test(tcno);
};
generator.isValidDate = function (dateValue) {
var datevalid = Date.parse(dateValue) === Nan ? false : true;
return datevalid;
};
generator.asyncValidators = {
emailNotValid: function (value) {
var deferred = $q.defer();
......@@ -641,7 +671,7 @@ angular.module('formService', ['ui.bootstrap'])
// todo: diff for all submits to recognize form change. if no change returns to view with no submit
angular.forEach($scope.ListNode, function (value, key) {
$scope.model[key] = value.model;
$scope.model[key] = value.items;
});
angular.forEach($scope.Node, function (value, key) {
$scope.model[key] = value.model;
......@@ -695,7 +725,7 @@ angular.module('formService', ['ui.bootstrap'])
$scope.$on('modalFormLocator', function (event) {
$scope.linkedModelForm = event.targetScope.linkedModelForm;
});
$scope.$on('submitModalForm', function () {
$scope.onSubmit($scope.linkedModelForm);
});
......@@ -715,7 +745,10 @@ angular.module('formService', ['ui.bootstrap'])
};
$scope.onNodeSubmit = function () {
$uibModalInstance.close($scope);
$scope.$broadcast('schemaFormValidate');
if ($scope.modalForm.$valid) {
$uibModalInstance.close($scope);
}
};
$scope.cancel = function () {
......@@ -736,7 +769,8 @@ angular.module('formService', ['ui.bootstrap'])
link: function (scope, element, attributes) {
element.on('click', function () {
var modalInstance = $uibModal.open({
animation: false,
animation: true,
backdrop: 'static',
templateUrl: 'shared/templates/listnodeModalContent.html',
controller: 'ModalCtrl',
size: 'lg',
......@@ -770,28 +804,28 @@ angular.module('formService', ['ui.bootstrap'])
form_params: {model: scope.node.schema.model_name}
};
Generator.generate(newscope, {forms:scope.node});
scope.model = {};
return scope.node;
Generator.generate(newscope, {forms: scope.node});
return newscope;
}
}
});
modalInstance.result.then(function (childmodel, key) {
//if (childmodel.schema.formType === 'Node') {
// scope.$parent.model[childmodel.schema.model_name] = childmodel.model;
//}
//
//if (childmodel.schema.formType === 'ListNode') {
// if (childmodel.edit) {
// scope.$parent[childmodel.schema.formType][childmodel.schema.model_name].model[childmodel.edit] = childmodel.model;
// } else {
// scope.$parent[childmodel.schema.formType][childmodel.schema.model_name].model.push(childmodel.model);
// }
//}
scope.$parent[childmodel.schema.formType][childmodel.schema.model_name].lengthModels += 1;
var listNodeItem = scope.$parent[childmodel.schema.formType][childmodel.schema.model_name];
if (childmodel.schema.formType === 'Node') {
listNodeItem.model = angular.copy(childmodel.model);
listNodeItem.lengthModels += 1;
}
if (childmodel.schema.formType === 'ListNode') {
if (childmodel.edit) {
listNodeItem.model[childmodel.edit] = childmodel.model;
} else {
listNodeItem.items.push(angular.copy(childmodel.model));
}
listNodeItem.lengthModels += 1;
}
});
});
}
......@@ -813,7 +847,7 @@ angular.module('formService', ['ui.bootstrap'])
element.on('click', function () {
var modalInstance = $uibModal.open({
animation: true,
backdrop:'static',
backdrop: 'static',
templateUrl: 'shared/templates/linkedModelModalContent.html',
controller: 'ModalCtrl',
size: 'lg',
......@@ -823,7 +857,11 @@ angular.module('formService', ['ui.bootstrap'])
url: scope.form.wf,
form_params: {model: scope.form.model_name, cmd: scope.form.add_cmd},
modalElements: {
buttonPositions: {bottom: 'move-to-bottom-modal', top: 'move-to-top-modal', none: ''},
buttonPositions: {
bottom: 'move-to-bottom-modal',
top: 'move-to-top-modal',
none: ''
},
workOnForm: 'linkedModelForm',
workOnDiv: '-modal'
},
......
......@@ -1520,6 +1520,34 @@ angular.module("shared/templates/linkedModelModalContent.html", []).run(["$templ
" <div class=\"buttons-on-top-modal\"></div>\n" +
" <hr>\n" +
" <form name=\"linkedModelForm\" sf-schema=\"schema\" sf-form=\"form\" sf-model=\"model\" modal-form-locator></form>\n" +
" <div ng-repeat=\"node in Node\">\n" +
" <h3>{{ node.title }}\n" +
" <span ng-if=\"node.lengthModels < 1\">\n" +
" <a href=\"javascript:void(0);\" modal-for-nodes=\"{{node.schema.model_name}},Node\">\n" +
" <i class=\"fa fa-plus-circle fa-fw\"></i>\n" +
" </a>\n" +
" </span>\n" +
" </h3>\n" +
"\n" +
" <div class=\"node-table\">\n" +
" <ng-include src=\"'shared/templates/nodeTable.html'\"></ng-include>\n" +
" </div>\n" +
" <hr>\n" +
" </div>\n" +
" <div ng-repeat=\"node in ListNode\">\n" +
" <h3>{{ node.title }}\n" +
" <span>\n" +
" <a href=\"javascript:void(0);\" modal-for-nodes=\"{{node.schema.model_name}},ListNode,add\">\n" +
" <i class=\"fa fa-plus-circle fa-fw\"></i>\n" +
" </a>\n" +
" </span>\n" +
" </h3>\n" +
"\n" +
" <div class=\"list-node-table\">\n" +
" <ng-include src=\"'shared/templates/nodeTable.html'\"></ng-include>\n" +
" </div>\n" +
" <hr>\n" +
" </div>\n" +
" <hr>\n" +
" <div class=\"buttons-on-bottom-modal\"></div>\n" +
"</div>\n" +
......@@ -1616,62 +1644,61 @@ angular.module("shared/templates/multiselect.html", []).run(["$templateCache", f
angular.module("shared/templates/nodeTable.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("shared/templates/nodeTable.html",
"<div class=\"tablescroll\">\n" +
" {{node.model}}\n" +
"<!--<table class=\"table table-bordered\" style=\"background-color:#fff;\">-->\n" +
" <!--<thead>-->\n" +
" <!--<tr ng-if=\"node.schema.formType=='Node'\">-->\n" +
" <!--&lt;!&ndash;<th colspan=\"2\">&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;<label>&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;<input type=\"checkbox\" style=\"zoom:1.5; margin:5px 0 0 8px;\">&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;Hepsini Seç&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;</label>&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;</th>&ndash;&gt;-->\n" +
" <!--<th ng-repeat=\"(key,value) in node.model\">{{ key }}</th>-->\n" +
" <!--<th>İşlem</th>-->\n" +
" <!--</tr>-->\n" +
" <!--<tr ng-if=\"node.schema.formType=='ListNode'\">-->\n" +
"<table class=\"table table-bordered\" style=\"background-color:#fff;\">\n" +
" <thead>\n" +
" <tr ng-if=\"node.schema.formType=='Node'\">\n" +
" <!--<th colspan=\"2\">-->\n" +
" <!--<label>-->\n" +
" <!--<input type=\"checkbox\" style=\"zoom:1.5; margin:5px 0 0 8px;\">-->\n" +
" <!--Hepsini Seç-->\n" +
" <!--</label>-->\n" +
" <!--</th>-->\n" +
" <!--<th ng-repeat=\"(key,value) in node.model[0]\">{{ key }}</th>-->\n" +
" <!--<th>İşlem</th>-->\n" +
" <!--</tr>-->\n" +
" <!--</thead>-->\n" +
" <!--<tbody ng-class=\"{hidden: node.lengthModels < 1}\">-->\n" +
"\n" +
" <!--<tr ng-if=\"node.schema.formType=='Node'\">-->\n" +
" <!--&lt;!&ndash;<td width=\"60\">&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;<label>&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;<input type=\"checkbox\" style=\"zoom:1.5; margin:5px 0 0 8px;\">&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;</label>&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;</td>&ndash;&gt;-->\n" +
" <!--&lt;!&ndash;<th scope=\"row\" style=\"text-align:center\">1</th>&ndash;&gt;-->\n" +
" <!--<td ng-repeat=\"value in node.model\">{{ value }}</td>-->\n" +
" <!--<td>-->\n" +
" <!--<button modal-for-nodes=\"{{node.schema.model_name}},{{node.schema.formType}},edit\">Düzenle</button><br>-->\n" +
" <!--<button>Sil</button>-->\n" +
" <!--</td>-->\n" +
" <!--</tr>-->\n" +
"\n" +
" <!--<tr ng-repeat=\"listnodemodel in node.model\" ng-if=\"node.schema.formType=='ListNode'\">-->\n" +
" <th ng-repeat=\"(key,value) in node.model track by $index\">{{ key }}</th>\n" +
" <th>İşlem</th>\n" +
" </tr>\n" +
" <tr ng-if=\"node.schema.formType=='ListNode'\">\n" +
" <th colspan=\"2\">\n" +
" <label>\n" +
" <input type=\"checkbox\" style=\"zoom:1.5; margin:5px 0 0 8px;\">\n" +
" Hepsini Seç\n" +
" </label>\n" +
" </th>\n" +
" <th ng-repeat=\"(key,value) in node.model track by $index\">{{ key }}</th>\n" +
" <th>İşlem</th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody ng-class=\"{hidden: node.lengthModels < 1}\">\n" +
"\n" +
" <tr ng-if=\"node.schema.formType=='Node'\">\n" +
" <!--<td width=\"60\">-->\n" +
" <!--<label>-->\n" +
" <!--<input type=\"checkbox\" style=\"zoom:1.5; margin:5px 0 0 8px;\">-->\n" +
" <!--</label>-->\n" +
" <!--</td>-->\n" +
" <!--<th scope=\"row\" style=\"text-align:center\">{{$index+1}}</th>-->\n" +
" <!--<td ng-repeat=\"(k, v) in listnodemodel\">{{ v }}</td>-->\n" +
" <!--<td>-->\n" +
" <!--<button modal-for-nodes=\"{{node.schema.model_name}},{{node.schema.formType}},edit,{{$index}}\">Düzenle</button><br>-->\n" +
" <!--<button>Sil</button>-->\n" +
" <!--</td>-->\n" +
" <!--</tr>-->\n" +
"\n" +
" <!--</tbody>-->\n" +
"<!--</table>-->\n" +
" <!--<th scope=\"row\" style=\"text-align:center\">1</th>-->\n" +
" <td ng-repeat=\"value in node.model track by $index\">{{ value }}</td>\n" +
" <td>\n" +
" <button modal-for-nodes=\"{{node.schema.model_name}},{{node.schema.formType}},edit\">Düzenle</button><br>\n" +
" <button>Sil</button>\n" +
" </td>\n" +
" </tr>\n" +
"\n" +
" <tr ng-repeat=\"listnodemodel in node.items track by $index\" ng-if=\"node.schema.formType=='ListNode'\">\n" +
" <td width=\"60\">\n" +
" <label>\n" +
" <input type=\"checkbox\" style=\"zoom:1.5; margin:5px 0 0 8px;\">\n" +
" </label>\n" +
" </td>\n" +
" <th scope=\"row\" style=\"text-align:center\">{{$index+1}}</th>\n" +
" <td ng-repeat=\"(k, v) in listnodemodel track by $index\">{{ v }}</td>\n" +
" <td>\n" +
" <button modal-for-nodes=\"{{node.schema.model_name}},{{node.schema.formType}},edit,{{$index}}\">Düzenle</button><br>\n" +
" <button>Sil</button>\n" +
" </td>\n" +
" </tr>\n" +
"\n" +
" </tbody>\n" +
"</table>\n" +
"</div>");
}]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment