-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
105 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,85 @@ | ||
angular.module('mwFormBuilder') | ||
.service('mwFormUuid', function () { | ||
function s4() { | ||
.service('mwFormUuid', function () { | ||
function s4() { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1); | ||
} | ||
this.get = function () { | ||
.toString(16) | ||
.substring(1); | ||
} | ||
|
||
this.get = function () { | ||
return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4(); | ||
|
||
|
||
}; | ||
}).factory('mwFormClone', ["mwFormUuid", function (mwFormUuid) { | ||
var service = {}; | ||
var checkedObjects = []; | ||
|
||
service.resetIds = function (obj, root) { | ||
if (root) { | ||
checkedObjects = []; | ||
} | ||
if (checkedObjects.indexOf(obj) >= 0) { | ||
return; | ||
} | ||
checkedObjects.push(obj); | ||
if (!obj === Object(obj)) { | ||
return; | ||
} | ||
}; | ||
}) | ||
.factory('mwFormClone', ["mwFormUuid", function (mwFormUuid) { | ||
var service = {}; | ||
var checkedObjects = []; | ||
|
||
if (Array.isArray(obj)) { | ||
obj.forEach(service.resetIds); | ||
return; | ||
} | ||
service.resetIds = function (obj, root) { | ||
if (root) { | ||
checkedObjects = []; | ||
} | ||
if (checkedObjects.indexOf(obj) >= 0) { | ||
return; | ||
} | ||
checkedObjects.push(obj); | ||
if (!obj === Object(obj)) { | ||
return; | ||
} | ||
|
||
for (var property in obj) { | ||
if (obj.hasOwnProperty(property)) { | ||
service.resetIds(obj[property]); | ||
} | ||
} | ||
if (Array.isArray(obj)) { | ||
obj.forEach(service.resetIds); | ||
return; | ||
} | ||
|
||
if (obj.hasOwnProperty('id')) { | ||
var newId = mwFormUuid.get(); | ||
var oldId = obj.id; | ||
obj.id = newId; | ||
} | ||
}; | ||
for (var property in obj) { | ||
if (obj.hasOwnProperty(property)) { | ||
service.resetIds(obj[property]); | ||
} | ||
} | ||
|
||
service.cloneElement = function (pageElement) { | ||
var element = {}; | ||
angular.copy(pageElement, element); | ||
service.resetIds(element, true); | ||
return element; | ||
}; | ||
if (obj.hasOwnProperty('id')) { | ||
var newId = mwFormUuid.get(); | ||
var oldId = obj.id; | ||
obj.id = newId; | ||
} | ||
}; | ||
|
||
service.clonePage = function (formPage) { | ||
var _page = {}; | ||
angular.copy(formPage, _page); | ||
_page.id = mwFormUuid.get(); | ||
var _elements = []; | ||
if (Array.isArray(formPage.elements)) { | ||
for (var i = 0; i < formPage.elements.length; i++) { | ||
_elements.push(service.cloneElement(formPage.elements[i])); | ||
} | ||
} | ||
_page.elements = _elements; | ||
return _page; | ||
}; | ||
service.cloneElement = function (pageElement) { | ||
var element = {}; | ||
angular.copy(pageElement, element); | ||
service.resetIds(element, true); | ||
return element; | ||
}; | ||
|
||
service.cloneForm = function (form) { | ||
var _form = {}; | ||
angular.copy(form, _form); | ||
var _pages = []; | ||
if (Array.isArray(form.pages)) { | ||
for (var i = 0; i < form.pages.length; i++) { | ||
_pages.push(service.clonePage(form.pages[i])); | ||
} | ||
} | ||
_form.pages = _pages; | ||
return _form; | ||
}; | ||
service.clonePage = function (formPage) { | ||
var _page = {}; | ||
angular.copy(formPage, _page); | ||
_page.id = mwFormUuid.get(); | ||
var _elements = []; | ||
if (Array.isArray(formPage.elements)) { | ||
for (var i = 0; i < formPage.elements.length; i++) { | ||
_elements.push(service.cloneElement(formPage.elements[i])); | ||
} | ||
} | ||
_page.elements = _elements; | ||
return _page; | ||
}; | ||
|
||
return service; | ||
service.cloneForm = function (form) { | ||
var _form = {}; | ||
angular.copy(form, _form); | ||
var _pages = []; | ||
if (Array.isArray(form.pages)) { | ||
for (var i = 0; i < form.pages.length; i++) { | ||
_pages.push(service.clonePage(form.pages[i])); | ||
} | ||
} | ||
_form.pages = _pages; | ||
return _form; | ||
}; | ||
|
||
}]); | ||
return service; | ||
|
||
/* .factory('CollectionsUtil', function(){ | ||
return{ | ||
replaceByEqualObject: function(collection, referenceObjects, equalFn){ | ||
return _.map(collection, function(element){ | ||
var foundRefObj = _.find(referenceObjects, function(refObj){ | ||
if(equalFn){ | ||
return equalFn(element, refObj); | ||
}else{ | ||
return _.isEqual(element, refObj); | ||
} | ||
}); | ||
if(foundRefObj){ | ||
return foundRefObj; | ||
}else{ | ||
return element; | ||
} | ||
}); | ||
}, | ||
isNotEmptyArray: function(object){ | ||
return object && $.isArray(object) && object.length > 0; | ||
} | ||
} | ||
});*/ | ||
}]); |