Commit fc34f09d authored by Bahadir Can Yildiz's avatar Bahadir Can Yildiz

Merge branch 'feature/5257' into develop

parents 57ad6e98 960b2b68
...@@ -292,7 +292,7 @@ svg.new-parent { ...@@ -292,7 +292,7 @@ svg.new-parent {
.djs-palette:not(.open) .djs-palette-entries { .djs-palette:not(.open) .djs-palette-entries {
display: none; display: none;
} }
confirm
.djs-palette .djs-palette-toggle:hover { .djs-palette .djs-palette-toggle:hover {
background: #666; background: #666;
} }
...@@ -304,7 +304,7 @@ svg.new-parent { ...@@ -304,7 +304,7 @@ svg.new-parent {
.highlighted-entry { .highlighted-entry {
color: rgb(255, 116, 0) !important; color: rgb(255, 116, 0) !important;
} }
confirm
/** /**
* context-pad * context-pad
*/ */
......
<div> <div>
<select ng-model="selection" ng-options="forms.indexOf(form) as form.name for form in forms" ng-change="selectform(selection)"> <select ng-model="selection" ng-options="trialList.indexOf(trial) as trial.name for trial in trialList" ng-change="selectform(selection)">
</select> </select>
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-xs-6 center"> <div class="col-xs-8 center">
<form sf-schema="schema" sf-form="form" sf-model="model"></form> <form sf-schema="schema" sf-form="form" sf-model="model"></form>
</div> </div>
</div> </div>
......
...@@ -6,29 +6,30 @@ ...@@ -6,29 +6,30 @@
* (GPLv3). See LICENSE.txt for details. * (GPLv3). See LICENSE.txt for details.
*/ */
var app=angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.formService']); angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.crud'])
app.controller('NewDesignsCtrl', function ($scope) {
.controller('NewDesignsCtrl', function ($scope) {
$scope.items = ['student', 'staff', 'academician']; $scope.items = ['student', 'staff', 'academician'];
$scope.selection = $scope.items[0]; $scope.selection = $scope.items[0];
}) })
.controller('FormServicePg', function ($scope, Generator, CrudUtility) {
/* /*
This controller is for testing new SchemaForm components. In addition, forms need to have the attribute: This controller is for testing new SchemaForm components. In addition, forms need to have the attribute:
"name" for defining the name shown in dropdown box. Paste the JSON of form as a member of $scope.forms. "name" for defining the name shown in dropdown box. Paste the JSON of form as a member of $scope.forms.
*/ */
$scope.trialList = [
app.controller('FormServicePg', function ($scope, Generator) {
$scope.forms = [
{ {
name: 'Deneme Form 1', name: 'Deneme Form 1',
form: ['email', 'id', 'name', 'novalid'], form: ['email', 'id', 'name', 'valid'],
schema: { schema: {
properties: { properties: {
email: {title: 'email', type: 'string'}, email: {title: 'email', type: 'string'},
id: {title: 'id', type: 'number'}, id: {title: 'id', type: 'number'},
name: {title: 'name', type: 'string'}, name: {title: 'name', type: 'string'},
novalid: { type: "button", cmd:"list_user2", title: "submit without validation", form_validate: false } valid: { type: 'submit', cmd:"list_user2", title: "submit with validation" }
}, required: ["email", "id", "name"], type: 'object', title: 'servicetest' }, required: ["email", "id", "name"], type: 'object', title: 'servicetest'
}, },
...@@ -37,26 +38,40 @@ var app=angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.formService'] ...@@ -37,26 +38,40 @@ var app=angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.formService']
} }
}, },
{ {
name: 'Deneme Form 2', name: 'Confirm Form Trial',
form: ['email', 'id', 'name'], form: ['email', 'id', 'name', 'confirm'],
schema: { schema: {
properties: { properties: {
email: {title: 'email', type: 'string'}, email: {title: 'email', type: 'string'},
id: {title: 'id', type: 'number'}, id: {title: 'id', type: 'number'},
name: {title: 'name', type: 'string'} name: {title: 'name', type: 'string'},
confirm: {
title: 'Confirm Form',
style:"btn-success",
type:'confirm',
confirm_message:"Lorem Ipsum Dolor Sit Amet",
buttons: [
{ text: "button 1", cmd:"zeaaa", style: "btn-warning"},
{ text: "button 2", cmd:"cmd1", style: "btn-success"}
],
readonly:"true",
form_validate: false}
}, required: [], type: 'object', title: 'servicetest' }, required: [], type: 'object', title: 'servicetest'
}, },
model: { model: {
email: 'test@test.com', id: 2, name: 'cageman' email: 'test@test.com', id: 3, name: 'cageman'
} }
} }
]; ];
$scope.form_params = {}; $scope.form_params = {};
$scope.selection = 0; $scope.selection = 0;
$scope.meta = {};
$scope.selectform = function (index) { $scope.selectform = function (index) {
var form = $scope.forms[index]; var data = { forms: $scope.trialList[index] };
$scope = Generator.generate($scope, {forms: form}); CrudUtility.listPageItems($scope, data);
Generator.generate($scope, data);
Generator.setPageData({pageData: false});
}; };
$scope.selectform($scope.selection); $scope.selectform($scope.selection);
}); });
\ No newline at end of file
...@@ -2,18 +2,19 @@ ...@@ -2,18 +2,19 @@
<button class="btn {{ form.style || 'btn-default' }}" <button class="btn {{ form.style || 'btn-default' }}"
type="button" type="button"
ng-disabled="form.readonly" ng-disabled="form.readonly"
uib-popover-template="'confirmPopoverTemplate.html'" ng-click="form.openModal()">
popover-title="{{form.title}}"
popover-placement="bottom"
popover-trigger="outsideClick">
<span ng-if="form.icon" class="{{form.icon}}"></span> <span ng-if="form.icon" class="{{form.icon}}"></span>
{{form.title}} {{form.title}}
</button> </button>
<script type="text/ng-template" id="confirmPopoverTemplate.html"> <!--<script type="text/ng-template" id="confirmModalTemplate.html">-->
<div>{{form.title}}</div> <!--<div class="modal-header">-->
<div class="form-group"> <!--<h3 class="modal-title">{{form.title}}</h3>-->
<p>{{form.confirm_message}}</p> <!--</div>-->
<button class="btn btn-default" ng-click="form.confirm()"></button> <!--<div class="modal-body">-->
</div> <!--<p>{{form.confirm_message}}</p>-->
</script> <!--</div>-->
<!--<div class="modal-footer">-->
<!--<button ng-repeat="b in form.buttons" class="btn {{b.style || 'btn-default'}}" type="button" ng-click="form.send(b.cmd,(b.dismiss || false))">{{b.text}}</button>-->
<!--</div>-->
<!--</script>-->
</div> </div>
\ No newline at end of file
<div class="modal-header">
<h3 class="modal-title">{{form.title}}</h3>
</div>
<div class="modal-body">
<p>{{form.confirm_message}}</p>
</div>
<div class="modal-footer">
<button ng-repeat="b in form.buttons" class="btn {{b.style || 'btn-default'}}" type="button" ng-click="form.onClick(b.cmd)">{{b.text}}</button>
</div>
\ No newline at end of file
<div class="form-group schema-form-submit {{form.htmlClass}}">
<button class="btn {{ form.style || 'btn-default' }}"
type="button"
ng-disabled="form.readonly"
uib-popover-template="'confirmPopoverTemplate.html'"
popover-title="{{form.title}}"
popover-trigger="none"
popover-placement="bottom"
popover-is-open="form.isOpen"
ng-click="form.clickHandler()">
<span ng-if="form.icon" class="{{form.icon}}"></span>
{{form.title}}
</button>
<script type="text/ng-template" id="confirmPopoverTemplate.html">
<div class="form-group">
<p>{{form.confirm_message}}</p>
<button class="btn btn-default" ng-click="form.confirm()">Confirm</button>
</div>
</script>
</div>
\ No newline at end of file
...@@ -3,6 +3,5 @@ ...@@ -3,6 +3,5 @@
<form name="modalForm" sf-schema="schema" sf-form="form" sf-model="model" modal-form-locator></form> <form name="modalForm" sf-schema="schema" sf-form="form" sf-model="model" modal-form-locator></form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="submit" class="btn btn-primary" ng-click="onNodeSubmit()">Tamam</button> <button ng-repeat="b in buttons" type="{{b.type}}" class="btn {{b.style || 'btn-default'}}" ng-click="onNodeBtnClk(b)">{{b.text}}</button>
<button type="button" class="btn btn-warning" ng-click="cancel()">İptal</button>
</div> </div>
\ No newline at end of file
...@@ -29,7 +29,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -29,7 +29,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @name Generator * @name Generator
* @description form service's Generator factory service handles all generic form operations * @description form service's Generator factory service handles all generic form operations
*/ */
.factory('Generator', function ($http, $q, $timeout, $sce, $location, $route, $compile, $log, RESTURL, $rootScope, Moment, WSOps, FormConstraints) { .factory('Generator', function ($http, $q, $timeout, $sce, $location, $route, $compile, $log, RESTURL, $rootScope, Moment, WSOps, FormConstraints, $uibModal) {
var generator = {}; var generator = {};
/** /**
* @memberof ulakbus.formService * @memberof ulakbus.formService
...@@ -286,6 +286,8 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -286,6 +286,8 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* *
* @returns scope {Object} * @returns scope {Object}
*/ */
generator.prepareFormItems = function (scope) { generator.prepareFormItems = function (scope) {
angular.forEach(scope.form, function (value, key) { angular.forEach(scope.form, function (value, key) {
...@@ -394,6 +396,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -394,6 +396,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
model_name: k, model_name: k,
inline_edit: scope.inline_edit inline_edit: scope.inline_edit
}, },
buttons: v.buttons,
url: scope.url, url: scope.url,
wf: v.wf || scope.wf, wf: v.wf || scope.wf,
quick_add: v.quick_add, quick_add: v.quick_add,
...@@ -607,21 +610,109 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -607,21 +610,109 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
}; };
} }
}, },
confirm: { //this field is a need for next features
confirmprev: {
default: function (scope, v, k) { default: function (scope, v, k) {
scope.form[scope.form.indexOf(k)] = { scope.form[scope.form.indexOf(k)] = {
type: "template", type: "template",
isOpen: false,
title: v.title, title: v.title,
confirm_message: v.confirm_message, confirm_message: v.confirm_message,
templateUrl: "shared/templates/confirm.html", templateUrl: "shared/templates/confirm.html",
name: k, name: k,
key: k, key: k,
cmd: v.cmd, cmd: v.cmd,
style: v.style,
clickHandler: function(){
this.isOpen = !this.isOpen;
},
confirm: function () { confirm: function () {
console.log(v.cmd); this.isOpen = false;
// send cmd with submit
delete scope.form_params.cmd;
scope.form_params['cmd'] = v.cmd;
generator.submit(scope, false);
}
};
}
},
confirm: {
default: function (scope, v, k) {
scope.form[scope.form.indexOf(k)] = {
type: "template",
title: v.title,
confirm_message: v.confirm_message,
templateUrl: "shared/templates/confirm.html",
name: k,
key: k,
style: v.style,
buttons: v.buttons,
modalInstance: "",
// buttons is an object array
//Example:
//buttons: [{
// text: "Button text",
// cmd: "button command",
// style: "btn-warning",
// dismiss: false --> this one is for deciding if the button can dismiss modal
//}]
modalFunction: function(){
delete scope.form_params.cmd;
delete scope.form_params.flow;
if (v.cmd) {
scope.form_params["cmd"] = v.cmd;
}
if (v.flow) {
scope.form_params["flow"] = v.flow;
}
if (v.wf) {
delete scope.form_params["cmd"];
scope.form_params["wf"] = v.wf;
}
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'shared/templates/confirmModalContent.html',
controller: 'ModalController',
resolve: {
items: function(){
var newscope = {
form: {
title: v.title,
confirm_message: v.confirm_message,
buttons: v.buttons,
onClick: function (cmd) {
// send cmd with submit // send cmd with submit
modalInstance.dismiss();
if (cmd) generator.submit(scope, false);
}
}
};
return newscope;
}
} }
});
},
openModal: function(){
var workOnForm = scope.modalElements ? scope.modalElements.workOnForm : 'formgenerated';
if (!v.form_validate && angular.isDefined(v.form_validate)){
this.modalFunction();
}
else{
scope.$broadcast('schemaFormValidate');
if (scope[workOnForm].$valid) {
this.modalFunction();
} else {
// focus to first input with validation error
$timeout(function () {
var firsterror = angular.element(document.querySelectorAll('input.ng-invalid'))[0];
firsterror.focus();
});
}
}
}
}; };
} }
}, },
...@@ -898,9 +989,6 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -898,9 +989,6 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {*} * @returns {*}
*/ */
generator.doItemAction = function ($scope, key, todo, mode) { generator.doItemAction = function ($scope, key, todo, mode) {
var _do = {
normal: function () {
$log.debug('normal mode starts');
$scope.form_params.cmd = todo.cmd; $scope.form_params.cmd = todo.cmd;
$scope.form_params.wf = $scope.wf; $scope.form_params.wf = $scope.wf;
if (todo.wf) { if (todo.wf) {
...@@ -919,10 +1007,43 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -919,10 +1007,43 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
$scope.form_params.id = $scope.param_id; $scope.form_params.id = $scope.param_id;
$scope.form_params.token = $scope.token; $scope.form_params.token = $scope.token;
var _do = {
normal: function () {
$log.debug('normal mode starts');
return generator.get_wf($scope); return generator.get_wf($scope);
}, },
modal: function () { modal: function () {
$log.debug('modal mode is not not ready'); $log.debug('modal mode starts');
var modalInstance = $uibModal.open({
animation: true,
backdrop: 'static',
keyboard: false,
templateUrl: 'shared/templates/confirmModalContent.html',
controller: 'ModalController',
size: '',
resolve: {
items: function () {
var newscope = {
form: {
buttons: [ { text: "Evet", style: "btn-success", cmd:"confirm" }, { text: "Hayir", "style": "btn-warning", dismiss: true } ],
title: todo.name,
confirm_message: "Islemi onayliyor musunuz?",
onClick: function(cmd){
modalInstance.close();
if (cmd === "confirm" && angular.isDefined(cmd)) {
modalInstance.close();
return generator.get_wf($scope);
}
}
}
}
return newscope;
}
}
});
}, },
new: function () { new: function () {
$log.debug('new mode is not not ready'); $log.debug('new mode is not not ready');
...@@ -1292,11 +1413,23 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1292,11 +1413,23 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
} }
}; };
$scope.onNodeSubmit = function () { $scope.onNodeBtnClk = function (button) {
if(!button.form_validate && angular.isDefined(button.form_validate)){
$uibModalInstance.close($scope);
}
else{
$scope.$broadcast('schemaFormValidate'); $scope.$broadcast('schemaFormValidate');
if ($scope.modalForm.$valid) { if ($scope.modalForm.$valid) {
$uibModalInstance.close($scope); $uibModalInstance.close($scope);
} }
else {
// focus to first input with validation error
$timeout(function () {
var firsterror = angular.element(document.querySelectorAll('input.ng-invalid'))[0];
firsterror.focus();
});
}
}
}; };
$scope.cancel = function () { $scope.cancel = function () {
......
...@@ -2843,8 +2843,7 @@ angular.module("shared/templates/listnodeModalContent.html", []).run(["$template ...@@ -2843,8 +2843,7 @@ angular.module("shared/templates/listnodeModalContent.html", []).run(["$template
" <form name=\"modalForm\" sf-schema=\"schema\" sf-form=\"form\" sf-model=\"model\" modal-form-locator></form>\n" + " <form name=\"modalForm\" sf-schema=\"schema\" sf-form=\"form\" sf-model=\"model\" modal-form-locator></form>\n" +
"</div>\n" + "</div>\n" +
"<div class=\"modal-footer\">\n" + "<div class=\"modal-footer\">\n" +
" <button type=\"submit\" class=\"btn btn-primary\" ng-click=\"onNodeSubmit()\">Tamam</button>\n" + " <button ng-repeat=\"b in schema.buttons\" type=\"{{b.type}}\" class=\"btn {{b.style || 'btn-default'}}\" ng-click=\"onNodeSubmit(b)\">{{b.text}}</button>\n" +
" <button type=\"button\" class=\"btn btn-warning\" ng-click=\"cancel()\">İptal</button>\n" +
"</div>"); "</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