Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 380 | Rev 384 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 380 Rev 382
Línea 7... Línea 7...
7
const Test = (props) => {
7
const Test = (props) => {
Línea 8... Línea 8...
8
 
8
 
9
    //init states 
9
    //init states 
10
    const [confirmationBoxShow, setConfirmationBoxShow] = useState(false);
10
    const [confirmationBoxShow, setConfirmationBoxShow] = useState(false);
-
 
11
    const [valid, setValid] = useState(false);
11
    const [valid, setValid] = useState(false);
12
    const [success, setSuccess] = useState(false);
Línea 12... Línea 13...
12
    const [page, setPage] = useState(0);
13
    const [page, setPage] = useState(0);
13
 
14
 
Línea 22... Línea 23...
22
            //init form data
23
            //init form data
23
            const formData = new FormData();
24
            const formData = new FormData();
24
            formData.append("content", JSON.stringify(test));
25
            formData.append("content", JSON.stringify(test));
25
            await axios.post(action, formData).then((response) => {
26
            await axios.post(action, formData).then((response) => {
26
                if (response.data.success) {
27
                if (response.data.success) {
27
                    setTest(null);
28
                    setSuccess(true);
28
                }
29
                }
29
            });
30
            });
30
        }
31
        }
31
    }
32
    }
32
    /**
33
    /**
Línea 55... Línea 56...
55
        });
56
        });
56
        validateForm();
57
        validateForm();
57
        setTest(test);
58
        setTest(test);
58
    }
59
    }
Línea -... Línea 60...
-
 
60
 
59
 
61
    /**
60
    const removeOptionMultiple = (arr, item) => {
62
     * Delete existing option
61
        console.log(arr);
63
     * @param {*} arr 
62
        var i = arr.indexOf(item);
64
     * @param {*} item 
63
        console.log(i);
65
     * @returns 
64
 
66
     */
65
        console.log(arr.splice(arr.indexOf(item), 1));
67
    const removeOptionMultiple = (arr, item) => arr.splice(arr.indexOf(item), 1);
66
        
-
 
67
        return arr.splice(arr.indexOf(item), 1);
-
 
68
    }
68
 
69
    /**
69
    /**
70
     * Check if there are questions to answer
70
     * Check if there are questions to answer
71
     * @returns 
71
     * @returns 
72
     */
72
     */
73
    const validateForm = () => {
73
    const validateForm = () => {
74
        let formValid = true;
74
        let formValid = true;
75
        test.content.map((section) => {
75
        test.content.map((section) => {
76
            section.questions.map((question) => {
76
            section.questions.map((question) => {
77
                //Validate if the answer is empty
77
                //Validate if the answer is empty
78
                if (!question.answer) {
78
                if (!question.answer || question.answer.length == 0) {
79
                    formValid = false;
79
                    formValid = false;
80
                }
80
                }
81
            })
81
            })
82
        })
82
        })
Línea 101... Línea 101...
101
            {loading ? (
101
            {loading ? (
102
                <div className="row">
102
                <div className="row">
103
                    <Spinner />
103
                    <Spinner />
104
                </div>
104
                </div>
105
            ) : (
105
            ) : (
-
 
106
                <div>
-
 
107
                    {!success ? (
106
                <div className="row test-section">
108
                        <div className="row test-section">
107
                    <div className="col-md-12 col-sm-12 col-xs-12">
109
                            <div className="col-md-12 col-sm-12 col-xs-12">
108
                        <div className="company-title">
110
                                <div className="company-title">
109
                            <div className="section_admin_title_buttons">
111
                                    <div className="section_admin_title_buttons">
110
                                <h1 className="title">{test.name}</h1>
112
                                        <h1 className="title">{test.name}</h1>
-
 
113
                                    </div>
-
 
114
                                </div>
-
 
115
                                <div
-
 
116
                                    dangerouslySetInnerHTML={{ __html: test.text }}
-
 
117
                                    className="description company-title"
-
 
118
                                ></div>
-
 
119
                            </div>
-
 
120
                            {test.content.length <= 0 ? (
-
 
121
                                <div className="col-md-12 col-sm-12 col-xs-12 text-center">
-
 
122
                                    {backendVars.LBL_DATATABLE_SZERORECORDS}
-
 
123
                                </div>
-
 
124
                            ) : (
-
 
125
                                <div className="col-md-12 col-sm-12 col-xs-12">
-
 
126
                                    <div className="company-title">
-
 
127
                                        {test.content.map((section, key) => {
-
 
128
                                            return <Section
-
 
129
                                                section={section}
-
 
130
                                                key={key}
-
 
131
                                                page={page}
-
 
132
                                                setPage={setPage}
-
 
133
                                                total={test.content.length}
-
 
134
                                                backendVars={backendVars}
-
 
135
                                                handleAnswer={handleAnswer}
-
 
136
                                            />
-
 
137
                                        })}
-
 
138
                                    </div>
-
 
139
                                </div>)}
-
 
140
                            <div className="col-md-12 col-sm-12 col-xs-12 text-right">
-
 
141
                                <div className="company-title">
-
 
142
                                    <button
-
 
143
                                        type="button"
-
 
144
                                        className="btn btn-secondary"
-
 
145
                                        onClick={handleConfirmationBoxShow}>
-
 
146
                                        {backendVars.LBL_CANCEL}
-
 
147
                                    </button>
-
 
148
 
-
 
149
                                    <ConfirmationBox
-
 
150
                                        show={confirmationBoxShow}
-
 
151
                                        onClose={handleConfirmationBoxShow}
-
 
152
                                        onAccept={handleCancel}
-
 
153
                                    />
-
 
154
 
-
 
155
 
-
 
156
                                    <button
-
 
157
                                        type="buttton"
-
 
158
                                        className="btn btn-primary"
-
 
159
                                        disabled={!valid}
-
 
160
                                        onClick={() => handleSubmit()}>
-
 
161
                                        {backendVars.LBL_SAVE}
-
 
162
                                    </button>
-
 
163
                                </div>
111
                            </div>
164
                            </div>
112
                        </div>
-
 
113
                        <div
-
 
114
                            dangerouslySetInnerHTML={{ __html: test.text }}
-
 
115
                            className="description company-title"
-
 
116
                        ></div>
-
 
117
                    </div>
-
 
118
                    {test.content.length <= 0 ? (
-
 
119
                        <div className="col-md-12 col-sm-12 col-xs-12 text-center">
-
 
120
                            {backendVars.LBL_DATATABLE_SZERORECORDS}
-
 
121
                        </div>
165
                        </div>
122
                    ) : (
166
                    ) : (
123
                        <div className="col-md-12 col-sm-12 col-xs-12">
167
                        <div className="row">
124
                            <div className="company-title">
168
                            <div className="col-md-12 col-sm-12 col-xs-12">
125
                                {test.content.map((section, key) => {
169
                                <h2>Su prueba se ha enviado con éxito</h2>
126
                                    return <Section
170
                                <a onClick={() => {
127
                                        section={section}
-
 
128
                                        key={key}
171
                                    setTest(null);
129
                                        page={page}
172
                                    setSuccess(false)
130
                                        setPage={setPage}
-
 
131
                                        total={test.content.length}
-
 
132
                                        backendVars={backendVars}
173
                                }}>{backendVars.LBL_GO_BACK}</a>
133
                                        handleAnswer={handleAnswer}
-
 
134
                                    />
-
 
135
                                })}
-
 
136
                            </div>
174
                            </div>
137
                        </div>)}
-
 
138
                    <div className="col-md-12 col-sm-12 col-xs-12 text-right">
-
 
139
                        <div className="company-title">
-
 
140
                            <button
-
 
141
                                type="button"
-
 
142
                                className="btn btn-secondary"
-
 
143
                                onClick={handleConfirmationBoxShow}>
-
 
144
                                {backendVars.LBL_CANCEL}
-
 
145
                            </button>
-
 
146
 
-
 
147
                            <ConfirmationBox
-
 
148
                                show={confirmationBoxShow}
-
 
149
                                onClose={handleConfirmationBoxShow}
-
 
150
                                onAccept={handleCancel}
-
 
151
                            />
-
 
152
 
-
 
153
 
-
 
154
                            <button
-
 
155
                                type="buttton"
-
 
156
                                className="btn btn-primary"
-
 
157
                                disabled={!valid}
-
 
158
                                onClick={() => handleSubmit()}>
-
 
159
                                {backendVars.LBL_SAVE}
-
 
160
                            </button>
-
 
161
                        </div>
175
                        </div>
162
                    </div>
176
                    )}
163
                </div>
177
                </div>
164
            )}
178
            )}
Línea 165... Línea 179...
165
 
179