UNPKG

ws-form-builder

Version:
87 lines 4.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var form_builder_1 = require("../../providers/form-builder/form-builder"); var WsPunchcardComponent = (function () { function WsPunchcardComponent(formBuilder) { this.formBuilder = formBuilder; this.answerGiven = new core_1.EventEmitter(); this.fieldValue = ''; this.isFieldValid = false; this.showError = false; this.fieldAnswers = {}; this.isDebug = false; this.fieldValue = ''; } WsPunchcardComponent.prototype.ngOnInit = function () { if (typeof this.question.xAxis !== 'undefined' && typeof this.question.yAxis !== 'undefined') { this.generateFields(); } if (typeof this.question.isDebug !== 'undefined' && this.question.isDebug === true) { this.isDebug = true; } }; WsPunchcardComponent.prototype.generateFields = function () { var data = {}; for (var i = 0; i < Object.keys(this.question.yAxis).length; i++) { //string = string+this.fieldAnswers[i]; var rowField = this.question.yAxis[i]['field']; if (typeof data[rowField] === 'undefined') { data[rowField] = {}; } for (var x = 0; x < Object.keys(this.question.xAxis).length; x++) { var colField = this.question.xAxis[x]['field']; data[rowField][colField] = false; } } this.fieldAnswers = data; //this.getFieldData(''); }; WsPunchcardComponent.prototype.getFieldData = function (key) { if (typeof this.question.data !== 'undefined') { } }; WsPunchcardComponent.prototype.setAnswer = function (event, question) { var isStringValid = this.validateAnswer(question, event.value); if (!isStringValid) { this.isFieldValid = false; this.showError = true; } else { this.isFieldValid = true; this.showError = false; } if (this.isFieldValid) { question.value = event.value; question.valid = true; this.answerGiven.emit(question); } }; WsPunchcardComponent.prototype.validateAnswer = function (question, string) { return this.formBuilder.validateAnswer(question, string); }; WsPunchcardComponent.prototype.updateCheckbox = function (event, row, col, question) { question.valid = true; this.fieldAnswers[row.field][col.field] = event.value; question.data = this.fieldAnswers; this.answerGiven.emit(question); }; WsPunchcardComponent.decorators = [ { type: core_1.Component, args: [{ selector: 'ws-punchcard', template: "\n <div class=\"ws-punchard-container\">\n \t<ion-grid>\n \t\t<ion-row>\n \t\t\t<ion-col></ion-col> <!-- add blank col for spacing -->\n \t\t\t<ion-col *ngFor=\"let col of question.xAxis; let i = index;\">\n \t\t\t\t<div class=\"xAxis-col col-{{col.field}}\" id=\"col-{{col.field}}\">\n \t\t\t\t\t<ion-icon name=\"md-star\"></ion-icon>\n \t\t\t\t\t<span class=\"col-label\">{{col.label}}</span>\n \t\t\t\t</div>\n\n \t\t\t</ion-col>\n \t\t</ion-row>\n\t\t\n \t\t<span *ngFor=\"let row of question.yAxis; let r = index;\">\n\n \t\t\t<ion-row>\n \t\t\t\t<ion-col>{{row.label}}</ion-col>\n\t\t\t\n \t\t\t<ion-col *ngFor=\"let col of question.xAxis; let c = index;\">\n \t\t\t\t<div class=\"body-col\">\n \t\t\t\t<ion-checkbox (ionChange)=\"updateCheckbox($event,row,col,question)\"></ion-checkbox>\n \t\t\t</div>\n \t\t\t</ion-col>\n \t\t\t</ion-row>\n \t\t</span>\n\n \t</ion-grid>\n </div>\n\n\n <pre style=\"max-height:150px;\" *ngIf=\"isDebug\">\n {{fieldAnswers | json}}\n </pre>\n ", styles: ["\n .ws-punchard-container .xAxis-col{text-align:center}.ws-punchard-container .xAxis-col .icon{display:block;font-size:30px}.ws-punchard-container .body-col{text-align:center}\n "] },] }, ]; /** @nocollapse */ WsPunchcardComponent.ctorParameters = function () { return [ { type: form_builder_1.FormBuilderProvider, }, ]; }; WsPunchcardComponent.propDecorators = { "question": [{ type: core_1.Input, args: ['question',] },], "answerGiven": [{ type: core_1.Output },], }; return WsPunchcardComponent; }()); exports.WsPunchcardComponent = WsPunchcardComponent; //# sourceMappingURL=ws-punchcard.js.map