Commit 21d02d95 authored by bahadircyildiz's avatar bahadircyildiz

CHANGE rref #5257. Confirm field attached.

parent ebee8ca7
...@@ -6,19 +6,15 @@ ...@@ -6,19 +6,15 @@
* (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.formService'])
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) {
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.forms = [
{ {
name: 'Deneme Form 1', name: 'Deneme Form 1',
...@@ -44,7 +40,16 @@ var app=angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.formService'] ...@@ -44,7 +40,16 @@ var app=angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.formService']
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: "zaaa xDê", cmd:"list_user", readonly:"true"} confirm: {
title: 'Confirm Form',
style:"btn-success",
type:'confirm',
confirm_message: "kelmangeeeeeeee kakooooo kakoooo şugarkeeeeee mageee kakoooo yandan geeeelll mage kakooooo kakoooo candan geeelll magee kakoooo mo kak kamiloooo biya westeee mo kak kamiloooo biya westeee me türbayyy dicaaa vilesgeee me haraaayy dicaaaa vilesgeeee voşdikeeelll mage kakoooo kakooo yandan geeeelll mage kakooo şugarkeeeee mageeee kakooo kakooooo candan geeell magee kakoooo gel mageeeee kakooo kakoooo şugarkeeee maneee kakooo yandan geeell mageee kakooo kakoooo candan geellll mane kakoooo mo kak kamiloooo biya westeee mo kak kamiloooo biya westeee me türbayyy dicaaa vilesgeee me haraaayy dicaaaa vilesgeeee voşdikeeelll mage kakoooo kakooo yandan geeeelll mage kakooo şugarkeeeee mageeee kakooo kakooooo candan geeell magee kakoooo.",
buttons: [
{ text: "button 1", style: "btn-warning", dismiss: true },
{ text: "button 2", cmd:"cmd1", style: "btn-success"},
],
readonly:"true"}
}, required: [], type: 'object', title: 'servicetest' }, required: [], type: 'object', title: 'servicetest'
}, },
model: { model: {
...@@ -58,9 +63,6 @@ var app=angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.formService'] ...@@ -58,9 +63,6 @@ var app=angular.module('ulakbus.uitemplates', ['ngRoute', 'ulakbus.formService']
$scope.selectform = function (index) { $scope.selectform = function (index) {
var form = $scope.forms[index]; var form = $scope.forms[index];
$scope = Generator.generate($scope, {forms: form}); $scope = Generator.generate($scope, {forms: form});
$timeout(function(){
$scope.$apply();
})
}; };
$scope.selectform($scope.selection); $scope.selectform($scope.selection);
}); });
\ No newline at end of file
...@@ -2,17 +2,19 @@ ...@@ -2,17 +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(form)">
popover-title="{{form.title}}"
popover-trigger="focus"
popover-placement="bottom">
<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 class="form-group"> <div class="modal-header">
<h3 class="modal-title">{{form.title}}</h3>
</div>
<div class="modal-body">
<p>{{form.confirm_message}}</p> <p>{{form.confirm_message}}</p>
<button class="btn btn-default" ng-click="form.confirm()">Confirm</button> </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> </div>
</script> </script>
</div> </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
...@@ -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
...@@ -609,10 +609,12 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -609,10 +609,12 @@ 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",
...@@ -620,32 +622,73 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -620,32 +622,73 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
key: k, key: k,
cmd: v.cmd, cmd: v.cmd,
style: v.style, style: v.style,
togglePopover: function(event){ clickHandler: function(){
this.isOpen = !this.isOpen;
}, },
confirm: function () { confirm: function () {
console.log(v.cmd); this.isOpen = false;
// send cmd with submit // send cmd with submit
delete scope.form_params.cmd;
scope.form_params['cmd'] = v.cmd;
generator.submit(scope, false); generator.submit(scope, false);
// .success(function(data){ }
// // response data contains object_id and unicode
// // scope.model can be reached via prototype chain };
// scope.model[formName] = data.forms.model.object_key; }
// // scope.form prototype chain returns this form item },
// scope.form.titleMap.push({ confirm: {
// value: data.forms.model.object_key, default: function (scope, v, k) {
// name: data.forms.model.unicode scope.form[scope.form.indexOf(k)] = {
// }); type: "template",
// scope.form.selected_item = { title: v.title,
// value: data.forms.model.object_key, confirm_message: v.confirm_message,
// name: data.forms.model.unicode templateUrl: "shared/templates/confirm.html",
// }; name: k,
// scope.$watch(document.querySelector('input[name=' + scope.form.model_name + ']'), key: k,
// function () { style: v.style,
// angular.element(document.querySelector('input[name=' + scope.form.model_name + ']')).val(scope.form.selected_item.name); 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(field){
this.modalInstance = $uibModal.open({
animation: true,
templateUrl: 'confirmModalTemplate.html',
controller: function ($scope){
$scope.form = field;
}
});
},
openModal: function(field){
if (!v.form_validate && angular.isDefined(v.form_validate)){
this.modalFunction(field);
}
else{
scope.$broadcast('schemaFormValidate');
if (scope.$valid === true) {
this.modalFunction(field);
scope.$broadcast('disposeModal');
} else {
// focus to first input with validation error
$timeout(function () {
var firsterror = angular.element(document.querySelectorAll('input.ng-invalid'))[0];
firsterror.focus();
});
}
}
},
send: function (cmd, dismiss) {
// send cmd with submit
delete scope.form_params.cmd;
scope.form_params['cmd'] = v.cmd;
if (dismiss) this.modalInstance.dismiss('cancel');
if (cmd) generator.submit(scope, false);
} }
}; };
......
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