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 {
.djs-palette:not(.open) .djs-palette-entries {
display: none;
}
confirm
.djs-palette .djs-palette-toggle:hover {
background: #666;
}
......@@ -304,7 +304,7 @@ svg.new-parent {
.highlighted-entry {
color: rgb(255, 116, 0) !important;
}
confirm
/**
* context-pad
*/
......
<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>
<div class="container">
<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>
</div>
</div>
......
......@@ -6,29 +6,30 @@
* (GPLv3). See LICENSE.txt for details.
*/
var app=angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.formService']);
app.controller('NewDesignsCtrl', function ($scope) {
angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.crud'])
.controller('NewDesignsCtrl', function ($scope) {
$scope.items = ['student', 'staff', 'academician'];
$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:
"name" for defining the name shown in dropdown box. Paste the JSON of form as a member of $scope.forms.
*/
app.controller('FormServicePg', function ($scope, Generator) {
$scope.forms = [
$scope.trialList = [
{
name: 'Deneme Form 1',
form: ['email', 'id', 'name', 'novalid'],
form: ['email', 'id', 'name', 'valid'],
schema: {
properties: {
email: {title: 'email', type: 'string'},
id: {title: 'id', type: 'number'},
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'
},
......@@ -37,26 +38,40 @@ var app=angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.formService']
}
},
{
name: 'Deneme Form 2',
form: ['email', 'id', 'name'],
name: 'Confirm Form Trial',
form: ['email', 'id', 'name', 'confirm'],
schema: {
properties: {
email: {title: 'email', type: 'string'},
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'
},
model: {
email: 'test@test.com', id: 2, name: 'cageman'
email: 'test@test.com', id: 3, name: 'cageman'
}
}
];
$scope.form_params = {};
$scope.selection = 0;
$scope.meta = {};
$scope.selectform = function (index) {
var form = $scope.forms[index];
$scope = Generator.generate($scope, {forms: form});
var data = { forms: $scope.trialList[index] };
CrudUtility.listPageItems($scope, data);
Generator.generate($scope, data);
Generator.setPageData({pageData: false});
};
$scope.selectform($scope.selection);
});
\ No newline at end of file
......@@ -2,18 +2,19 @@
<button class="btn {{ form.style || 'btn-default' }}"
type="button"
ng-disabled="form.readonly"
uib-popover-template="'confirmPopoverTemplate.html'"
popover-title="{{form.title}}"
popover-placement="bottom"
popover-trigger="outsideClick">
ng-click="form.openModal()">
<span ng-if="form.icon" class="{{form.icon}}"></span>
{{form.title}}
</button>
<script type="text/ng-template" id="confirmPopoverTemplate.html">
<div>{{form.title}}</div>
<div class="form-group">
<p>{{form.confirm_message}}</p>
<button class="btn btn-default" ng-click="form.confirm()"></button>
</div>
</script>
<!--<script type="text/ng-template" id="confirmModalTemplate.html">-->
<!--<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.send(b.cmd,(b.dismiss || false))">{{b.text}}</button>-->
<!--</div>-->
<!--</script>-->
</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 @@
<form name="modalForm" sf-schema="schema" sf-form="form" sf-model="model" modal-form-locator></form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" ng-click="onNodeSubmit()">Tamam</button>
<button type="button" class="btn btn-warning" ng-click="cancel()">İptal</button>
<button ng-repeat="b in buttons" type="{{b.type}}" class="btn {{b.style || 'btn-default'}}" ng-click="onNodeBtnClk(b)">{{b.text}}</button>
</div>
\ No newline at end of file
......@@ -29,7 +29,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @name Generator
* @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 = {};
/**
* @memberof ulakbus.formService
......@@ -286,6 +286,8 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
*
* @returns scope {Object}
*/
generator.prepareFormItems = function (scope) {
angular.forEach(scope.form, function (value, key) {
......@@ -394,6 +396,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
model_name: k,
inline_edit: scope.inline_edit
},
buttons: v.buttons,
url: scope.url,
wf: v.wf || scope.wf,
quick_add: v.quick_add,
......@@ -607,24 +610,112 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
};
}
},
confirm: {
//this field is a need for next features
confirmprev: {
default: function (scope, v, k) {
scope.form[scope.form.indexOf(k)] = {
type: "template",
isOpen: false,
title: v.title,
confirm_message: v.confirm_message,
templateUrl: "shared/templates/confirm.html",
name: k,
key: k,
cmd: v.cmd,
style: v.style,
clickHandler: function(){
this.isOpen = !this.isOpen;
},
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
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();
});
}
}
}
};
}
},
date: {
default: function (scope, v, k) {
$log.debug('date:', scope.model[k]);
......@@ -898,31 +989,61 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* @returns {*}
*/
generator.doItemAction = function ($scope, key, todo, mode) {
$scope.form_params.cmd = todo.cmd;
$scope.form_params.wf = $scope.wf;
if (todo.wf) {
$scope.url = todo.wf;
$scope.form_params.wf = todo.wf;
delete $scope.token;
delete $scope.form_params.model;
delete $scope.form_params.cmd
}
if (todo.object_key) {
$scope.form_params[todo.object_key] = key;
} else {
$scope.form_params.object_id = key;
}
$scope.form_params.param = $scope.param;
$scope.form_params.id = $scope.param_id;
$scope.form_params.token = $scope.token;
var _do = {
normal: function () {
$log.debug('normal mode starts');
$scope.form_params.cmd = todo.cmd;
$scope.form_params.wf = $scope.wf;
if (todo.wf) {
$scope.url = todo.wf;
$scope.form_params.wf = todo.wf;
delete $scope.token;
delete $scope.form_params.model;
delete $scope.form_params.cmd
}
if (todo.object_key) {
$scope.form_params[todo.object_key] = key;
} else {
$scope.form_params.object_id = key;
}
$scope.form_params.param = $scope.param;
$scope.form_params.id = $scope.param_id;
$scope.form_params.token = $scope.token;
return generator.get_wf($scope);
},
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 () {
$log.debug('new mode is not not ready');
......@@ -1292,11 +1413,23 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
}
};
$scope.onNodeSubmit = function () {
$scope.$broadcast('schemaFormValidate');
if ($scope.modalForm.$valid) {
$scope.onNodeBtnClk = function (button) {
if(!button.form_validate && angular.isDefined(button.form_validate)){
$uibModalInstance.close($scope);
}
else{
$scope.$broadcast('schemaFormValidate');
if ($scope.modalForm.$valid) {
$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 () {
......
......@@ -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" +
"</div>\n" +
"<div class=\"modal-footer\">\n" +
" <button type=\"submit\" class=\"btn btn-primary\" ng-click=\"onNodeSubmit()\">Tamam</button>\n" +
" <button type=\"button\" class=\"btn btn-warning\" ng-click=\"cancel()\">İptal</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" +
"</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