2 var stepFormFactory = function($http, $compile, $q, $log) {
6 factory.getStepJSONData = function(jsonSrcName) {
10 }).then(function(response) {
11 if (typeof response.data === 'object') {
14 return $q.reject(response.data);
16 }, function(response) {
17 // something went wrong
18 return $q.reject(response.data);
23 factory.renderColumnForm = function(scope) {
26 factory.renderForm = function(jsonSrcName, elem, scope) {
27 let defer = $q.defer();
28 var divStepForm = document.getElementById('stepView');
29 var textStyle = "width:300px"
30 var textAreaStyle = "width:300px"
32 while(divStepForm && divStepForm.firstChild){
33 divStepForm.removeChild(divStepForm.firstChild);
38 }).then(function successCallback(response) {
39 // this callback will be called asynchronously
40 // when the response is available
41 if (typeof response.data === 'object') {
42 var json = response.data;
44 var div =d3.select(elem[0]);
45 var modelNameDict = {};
47 div.append("h1").attr({"class":"font-color:blue"}).text(json.content.title);
48 div.append("div").html(json.content.contentHtml);
49 var sections = json.content.sections;
50 sections.forEach(function(d, i) {
51 var sectionDiv = div.append("div");
52 sectionDiv.attr("id", "section_"+i);
53 if(d.title != "finalButton")
54 sectionDiv.append("h4").text(d.title);
55 var proj_id_hidden = sectionDiv.append("input");
56 proj_id_hidden.attr({"type":"hidden", "value":"", "name": "proj_id", "ng-model":"proj_id", "style": "" });
58 var elements = d.elements;
59 var buttons = d.buttons;
62 elements.forEach(function(element, elementIndex) {
65 if(elementIndex == 0) {
66 elementTable = sectionDiv.append("table").attr({"border":"0", "cellpadding":"4", "cellspacing":"0"});
67 elementBody = elementTable.append("tbody");
69 elementBody = elementTable = sectionDiv.select("tbody");
71 if(element.input == 'hidden') {
74 var tr = elementBody.append("tr")
75 var cellWidthStyle = {"width":"50%"}
77 if (!(element.spanOverTwoColumns)){
78 var td = tr.append("td").attr({"width":"30%","class":"tdLeftColumn"});
79 if (element.input=="checkboxGroup") {
80 td = td.attr({"rowspan":element.checkboxes.length})
82 td.text(element.displayName);
83 var cellWidthStyle = {"width":"500px;"}
85 td = tr.append("td").attr(cellWidthStyle);
86 var model_name_appendix='';
87 if (element.name in modelNameDict) {
88 modelNameDict[element.name]=modelNameDict[element.name]+1
89 model_name_appendix ='_'+modelNameDict[element.name]
91 modelNameDict[element.name]=0
93 if(element.input == 'text') {
94 var inp_text = td.append("input");
95 inp_text.attr({"type":"text", "value":element.defaultValue, "name": element.name, "ng-model":element.name+model_name_appendix, "style": (element.style?element.style:textStyle) });
97 else if(element.input === 'checkbox') {
98 var temptd= td.append("label").attr({"class":"checkbox"});
99 var temptd2= temptd.append("input").attr({"type":"checkbox", "ng-model": element.checkbox.value});
100 var temptd3= temptd.append("i").attr({"class":"skin"})
101 var temptd3= temptd.append("span").text(element.checkbox.text);
103 } else if (element.input === 'radio') {
104 element.options.forEach(function(d,i) {
105 td.append("input").attr({"type":"radio", "id":element.name+"_"+d.id, "ng-model":element.name+model_name_appendix, "name": element.name, "value": d.id});
106 td.append("label").text(d.name);
108 } else if (element.input === 'checkboxGroup') {
110 element.checkboxes.forEach(function(d,i) {
112 var temptd= td.append("label").attr({"class":"checkbox"});
113 var temptd2= temptd.append("input").attr({"type":"checkbox", "ng-model": d.value});
114 var temptd3= temptd.append("i").attr({"class":"skin"})
115 var temptd3= temptd.append("span").text(d.text);
117 var tr = elementBody.append("tr")
118 td = tr.append("td").attr({"width":"50%"});
119 var temptd= td.append("label").attr({"class":"checkbox"});
120 var temptd2= temptd.append("input").attr({"type":"checkbox", "ng-model": d.value});
121 var temptd3= temptd.append("i").attr({"class":"skin"})
122 var temptd3= temptd.append("span").text(d.text);
125 } else if (element.input === 'textarea') {
126 td.append("textarea").attr({"rows":"4", "cols":"50", "ng-model":element.name+model_name_appendix, "name": element.name, "style": (element.style?element.style:textAreaStyle)});
128 else if (element.input === 'select') {
129 var select = td.append("select");
130 // need to store options into element name;
132 .attr({"name": element.name,"b2b-dropdown":"","ng-model":element.ngModelName,"style":"width:300px"})
133 .attr("placeholder-text","Select");
136 /* var data = ["Option 1", "Option 2", "Option 3"]*/
139 .data(element.options).enter()
140 .append('option').attr("value", function(d) {return d.value})
141 .attr("b2b-dropdown-list","")
142 .text(function (d) { return d.text; })
144 } else if (element.input === 'tabletext') {
145 var colArray = element.columns.split(',');
146 var table = td.append("table");
147 table.attr("border", "1");
149 colArray.forEach(function(d) {
150 table.append("th").text(d);
157 buttons.forEach(function(button, buttonIndex) {
158 sectionDiv.append("input").attr({"type":"button", "value": button.text, "ng-click":button.ngFunction,"class":"btn btn-alt btn-small"});
160 sectionDiv.append("br");
164 if((json.step != "1")&&(!json.hideBackButton))
165 sectionDiv.append("input").attr({"type":"button", "value": "Back", "ng-click":"previous()","class":"btn btn-alt btn-small"});
166 if((d.title == "finalButton")&(!json.hideSaveButton))
167 sectionDiv.append("input").attr({"type":"button", "value": "Save", "ng-click":"save()", "class":"btn btn-alt btn-small"});
169 sectionDiv.append("input").attr({"type":"button", "value": "Next", "ng-click":"next()", "class":"btn btn-alt btn-small"});
173 elem.html(div.html());
174 elem.removeAttr("step-form");
175 $compile(elem.contents())(scope);
179 return $q.reject(response.data);
181 }, function errorCallback(response) {
182 // called asynchronously if an error occurs
183 // or server returns response with an error status.
184 $log.error("reponse data is not a valid JSON object");
188 return defer.promise;
194 stepFormFactory.$inject = ['$http', '$compile', '$q'];
196 appDS2.factory('stepFormFactory', stepFormFactory);