Commit b444025f authored by Vladimir Baranov's avatar Vladimir Baranov

FIX, rfix #5400. Fix modal form submit for linked models. Fix add multiple listNodes bug

parent 6d6af8d8
...@@ -461,6 +461,8 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -461,6 +461,8 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
} }
}); });
// todo: check this place to fix 'keys instead of names' bug
if (scope.model[k]) { if (scope.model[k]) {
angular.forEach(scope.model[k], function (value, key) { angular.forEach(scope.model[k], function (value, key) {
angular.forEach(value, function (y, x) { angular.forEach(value, function (y, x) {
...@@ -1166,6 +1168,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1166,6 +1168,7 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
// $rootScope.$broadcast('reload_cmd', $scope.reload_cmd); // $rootScope.$broadcast('reload_cmd', $scope.reload_cmd);
// //return; // //return;
//} //}
/** /**
* @memberof ulakbus.formService * @memberof ulakbus.formService
* @ngdoc function * @ngdoc function
...@@ -1325,10 +1328,11 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1325,10 +1328,11 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
* *
* @param {Object} $scope * @param {Object} $scope
* @param {Object} redirectTo * @param {Object} redirectTo
* @param {Boolean} dontProcessReply - used in modal forms
* @returns {*} * @returns {*}
* @todo diff for all submits to recognize form change. if no change returns to view with no submit * @todo diff for all submits to recognize form change. if no change returns to view with no submit
*/ */
generator.submit = function ($scope, redirectTo) { generator.submit = function ($scope, redirectTo, dontProcessReply) {
/** /**
* In case of unformatted date object in any key recursively, it must be converted. * In case of unformatted date object in any key recursively, it must be converted.
...@@ -1366,9 +1370,12 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1366,9 +1370,12 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
}; };
if ($rootScope.websocketIsOpen === true) { if ($rootScope.websocketIsOpen === true) {
WSOps.request(send_data) return WSOps.request(send_data)
.then(function (data) { .then(function (data) {
return generator.pathDecider(data.client_cmd || ['list'], $scope, data); if (!dontProcessReply){
return generator.pathDecider(data.client_cmd || ['list'], $scope, data);
}
return data;
}); });
} else { } else {
$timeout(function () { $timeout(function () {
...@@ -1514,6 +1521,14 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1514,6 +1521,14 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
var reformattedModel = {}; var reformattedModel = {};
angular.forEach(childmodel.model, function (value, key) { angular.forEach(childmodel.model, function (value, key) {
if (key.indexOf('_id') > -1) { if (key.indexOf('_id') > -1) {
// todo: understand why we got object here!
// hack to fix bug with value as object
if (angular.isObject(value) && value.value){
value = value.value;
childmodel.model[key] = value;
}
angular.forEach(childmodel.form, function (v, k) { angular.forEach(childmodel.form, function (v, k) {
if (v.formName === key) { if (v.formName === key) {
//if (!childmodel.model[key].key) { //if (!childmodel.model[key].key) {
...@@ -1522,11 +1537,15 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1522,11 +1537,15 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
return element; return element;
} }
} }
var unicodeValue = v.titleMap.find(indexInTitleMap);
if (unicodeValue){
unicodeValue = unicodeValue.name;
reformattedModel[key] = {
"key": value,
"unicode": unicodeValue
}
}
reformattedModel[key] = {
"key": value,
"unicode": v.titleMap.find(indexInTitleMap).name
};
//} //}
} }
}); });
...@@ -1616,27 +1635,18 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1616,27 +1635,18 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
modalInstance.result.then(function (childscope, key) { modalInstance.result.then(function (childscope, key) {
var formName = childscope.formName; var formName = childscope.formName;
Generator.submit(childscope, false) Generator.submit(childscope, false, true).then(
.success(function (data) { function (data) {
// response data contains object_id and unicode // response data contains object_id and unicode
// scope.model can be reached via prototype chain // scope.form can be reached via prototype chain
scope.model[formName] = data.forms.model.object_key; var item = {
// scope.form prototype chain returns this form item
scope.form.titleMap.push({
value: data.forms.model.object_key,
name: data.forms.model.unicode
});
scope.form.selected_item = {
value: data.forms.model.object_key, value: data.forms.model.object_key,
name: data.forms.model.unicode name: data.forms.model.unicode
}; };
scope.$watch(document.querySelector('input[name=' + scope.form.model_name + ']'), scope.form.titleMap.push(item);
function () { scope.form.onSelect(item, formName);
angular.element(document.querySelector('input[name=' + scope.form.model_name + ']')).val(scope.form.selected_item.name);
}
);
}); });
//$route.reload();
}); });
}); });
} }
...@@ -1656,4 +1666,4 @@ angular.module('ulakbus.formService', ['ui.bootstrap']) ...@@ -1656,4 +1666,4 @@ angular.module('ulakbus.formService', ['ui.bootstrap'])
scope.$emit('modalFormLocator'); scope.$emit('modalFormLocator');
} }
} }
}); });
\ No newline at end of file
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