got field duplicate button to work
This commit is contained in:
parent
3d63357831
commit
942f6b73dc
|
@ -35,48 +35,7 @@ angular.module('forms').directive('autoSaveForm', ['$rootScope', '$timeout', fun
|
|||
return false;
|
||||
};
|
||||
|
||||
var debounceUpdates = function () {
|
||||
|
||||
// console.log('Saving Form');
|
||||
if(savePromise) {
|
||||
$timeout.cancel(savePromise);
|
||||
}else {
|
||||
savePromise = $timeout(function() {
|
||||
|
||||
|
||||
$rootScope[$attrs.autoSaveCallback](
|
||||
function(err){
|
||||
if(!err){
|
||||
// console.log('\n\nForm data persisted -- setting pristine flag');
|
||||
// console.log('\n\n---------\nUpdate form CLIENT');
|
||||
// console.log(Date.now());
|
||||
$formCtrl.$setPristine();
|
||||
console.log($rootScope.saveInProgress);
|
||||
savePromise = null;
|
||||
// $formCtrl.$setUntouched();
|
||||
}else{
|
||||
console.error('Error form data NOT persisted');
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// $scope.$watch('editForm', function(newValue, oldValue) {
|
||||
// console.log('watch editForm');
|
||||
// if($scope.anyDirtyAndTouched($scope.editForm)){
|
||||
// console.log('ready to save text input');
|
||||
// }
|
||||
// });
|
||||
|
||||
$scope.$watch(function(newValue, oldValue) {
|
||||
// console.log('watch editForm');
|
||||
if($scope.anyDirtyAndTouched($scope.editForm) && !$rootScope.saveInProgress){
|
||||
console.log('ready to save text input');
|
||||
console.log('Saving Form');
|
||||
var updateFields = function () {
|
||||
$rootScope.saveInProgress = true;
|
||||
$rootScope[$attrs.autoSaveCallback](false,
|
||||
function(err){
|
||||
|
@ -91,6 +50,14 @@ angular.module('forms').directive('autoSaveForm', ['$rootScope', '$timeout', fun
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$scope.$watch(function(newValue, oldValue) {
|
||||
if($scope.anyDirtyAndTouched($scope.editForm) && !$rootScope.saveInProgress){
|
||||
console.log('ready to save text input');
|
||||
console.log('Saving Form');
|
||||
updateFields();
|
||||
}
|
||||
});
|
||||
|
||||
//Autosave Form when model (specificed in $attrs.autoSaveWatch) changes
|
||||
|
@ -109,37 +76,17 @@ angular.module('forms').directive('autoSaveForm', ['$rootScope', '$timeout', fun
|
|||
// console.log('newValue: '+newValue);
|
||||
// console.log('oldValue: '+oldValue);
|
||||
|
||||
// var anyCurrentlyDirtyNotFocused = $scope.anyDirtyAndTouched($scope.editForm);
|
||||
// console.log('anyCurrentlyDirtyNotFocused: '+anyCurrentlyDirtyNotFocused);
|
||||
// console.log('properties of $scope.editForm');
|
||||
// for(var item in $scope.editForm){
|
||||
// console.log(item);
|
||||
// }
|
||||
//Save form ONLY IF rendering is finished, form_fields have been change AND currently not save in progress
|
||||
if($rootScope.finishedRender && (changedFields && !$formCtrl.$dirty) && !$rootScope.saveInProgress) {
|
||||
|
||||
|
||||
if(savePromise) {
|
||||
$timeout.cancel(savePromise);
|
||||
savePromise = null;
|
||||
}
|
||||
|
||||
savePromise = $timeout(function() {
|
||||
|
||||
console.log('Saving Form');
|
||||
$rootScope.saveInProgress = true;
|
||||
$rootScope[$attrs.autoSaveCallback](false,
|
||||
function(err){
|
||||
if(!err){
|
||||
console.log('\n\nForm data persisted -- setting pristine flag');
|
||||
// console.log('\n\n---------\nUpdate form CLIENT');
|
||||
// console.log(Date.now());
|
||||
$formCtrl.$setPristine();
|
||||
}else{
|
||||
console.error('Error form data NOT persisted');
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
updateFields();
|
||||
});
|
||||
}else if($rootScope.finishedRender && $rootScope.saveInProgress){
|
||||
$rootScope.saveInProgress = false;
|
||||
|
|
|
@ -92,7 +92,7 @@ angular.module('forms')
|
|||
** Field CRUD Methods
|
||||
*/
|
||||
// Add a new field
|
||||
$scope.addNewField = function(fieldType){
|
||||
$scope.addNewField = function(addOrReturn, fieldType){
|
||||
|
||||
// incr field_id counter
|
||||
$scope.addField.lastAddedID++;
|
||||
|
@ -116,8 +116,13 @@ angular.module('forms')
|
|||
};
|
||||
|
||||
// put newField into fields array
|
||||
if(addOrReturn){
|
||||
$scope.myform.form_fields.push(newField);
|
||||
// console.log('\n\n---------\nAdded field CLIENT');
|
||||
}else {
|
||||
return newField;
|
||||
}
|
||||
|
||||
console.log('\n\n---------\nAdded field CLIENT');
|
||||
// console.log(Date.now());
|
||||
// console.log($scope.myform.form_fields.length);
|
||||
};
|
||||
|
@ -133,13 +138,21 @@ angular.module('forms')
|
|||
}
|
||||
}
|
||||
};
|
||||
$scope.duplicateField = function (field, field_index){
|
||||
for(var i = 0; i < $scope.myform.form_fields.length; i++){
|
||||
if($scope.myform.form_fields[i].field_id === field.field_id){
|
||||
$scope.addNewField($scope.myform.form_fields[i].fieldType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$scope.duplicateField = function (field_index){
|
||||
console.log('field_index: '+field_index);
|
||||
var field = $scope.addNewField(false, $scope.myform.form_fields[field_index].fieldType);
|
||||
field.title = $scope.myform.form_fields[field_index].title;
|
||||
console.log($scope.myform.form_fields[field_index]);
|
||||
|
||||
|
||||
//Insert field at selected index
|
||||
$scope.myform.form_fields.splice(field_index+1, 0, field);
|
||||
// for(var i = 0; i < $scope.myform.form_fields.length; i++){
|
||||
// if($scope.myform.form_fields[i].field_id === field.field_id){
|
||||
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -2,17 +2,14 @@
|
|||
<form class="row" name="editForm" auto-save-form auto-save-watch="myform.form_fields" auto-save-callback="update">
|
||||
|
||||
<div class="col-xs-5 add-field" id="hello">
|
||||
<!-- <select ng-model="addField.new" ng-options="type.name as type.value for type in addField.types"></select>
|
||||
<button type="submit" class="btn" ng-click="addNewField()">
|
||||
<i class="icon-plus"></i> Add Field
|
||||
</button> -->
|
||||
|
||||
<div class="row add-field-title">
|
||||
<h3 class="col-xs-12">Add New Field</h3>
|
||||
</div>
|
||||
<div class="panel-group row" class="draggable" ng-model="addField.types">
|
||||
<div class="col-xs-6" ng-repeat="type in addField.types">
|
||||
<div class="panel panel-default" style="background-color:#f5f5f5;">
|
||||
<div class="panel-heading" ng-click="addNewField(type.name)" style="cursor: pointer; font-size:14px;">
|
||||
<div class="panel-heading" ng-click="addNewField(true, type.name)" style="cursor: pointer; font-size:14px;">
|
||||
<span class="pull-left">
|
||||
<field-icon-directive type-name="{{type.name}}"></field-icon-directive>
|
||||
</span>
|
||||
|
@ -132,7 +129,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row"><br><hr></div>
|
||||
<!-- <div class="row"><br><hr></div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-4 col-sm-offset-4">
|
||||
|
@ -140,7 +137,7 @@
|
|||
<i class="icon-arrow-left icon-white"></i> Save Changes
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</accordion-group>
|
||||
|
||||
|
@ -168,7 +165,7 @@
|
|||
<div class="col-xs-1" style="padding:0 5px;">
|
||||
<div class="panel-group tool-panel text-center">
|
||||
<div class="panel panel-default" ng-repeat="field in myform.form_fields" ng-if="!field.deletePreserved">
|
||||
<div class="panel-heading" style="padding: 10px 10px; height: 37px;" ng-click="duplicateField(field, $index)">
|
||||
<div class="panel-heading" style="padding: 10px 10px; height: 37px;" ng-click="duplicateField($index)">
|
||||
<span class="text-center">
|
||||
<a href="" class="fa fa-files-o"></a>
|
||||
</span>
|
||||
|
|
Loading…
Reference in a new issue