How to use single_type method in wpt

Best JavaScript code snippet using wpt

MHDatePicker.js

Source:MHDatePicker.js Github

copy

Full Screen

1import PropTypes from 'prop-types';2import React from 'react';3import { Dimensions, Modal, Platform, StyleSheet, Text, TouchableHighlight, TouchableWithoutFeedback, View } from 'react-native';4import { strings, Styles } from '../resources';5import { formatString } from '../resources/Strings';6import Separator from './Separator';7import StringSpinner from "./StringSpinner";8/**9 * @description 时间选择器类型10 * @enum {string}11 */12const TYPE = {13 /**14 * 单个picker15 */16 SINGLE: 'single',17 /**18 * 选择小时分钟,24小时制19 */20 TIME24: 'time24',21 /**22 * 选择小时分钟,12小时制23 */24 TIME12: 'time12',25 /**26 * 选择年月日27 */28 DATE: 'date'29}30Object.freeze(TYPE);31/**32 * @description 单个picker时选择器的类型,也就是显示的单位33 * @enum {string}34 */35const SINGLE_TYPE = {36 /**37 * 月38 */39 MONTH: 'month',40 /**41 * 日42 */43 DAY: 'day',44 /**45 * 时46 */47 HOUR: 'hour',48 /**49 * 分50 */51 MINUTE: 'minute',52 /**53 * 秒54 */55 SECOND: 'second'56}57Object.freeze(SINGLE_TYPE);58/**59 * 60 * @param {number} length 61 * @param {bool} zeroPrefix 是否前补062 * @param {bool} fromZero 是否从0开始63 */64function constructArray(length, zeroPrefix = true, fromZero = false) {65 const maxLength = (length - (fromZero ? 1 : 0)).toString().length;66 return Array.from({ length }, (v, i) => {67 return ((zeroPrefix ? '0000000000000' : '') + (i + (fromZero ? 0 : 1))).slice(-maxLength);68 });69}70const screenBackgroundColor = 'rgba(0,0,0,0.4)';71const margin = 10;72const borderRadius = 15;73const titleHeightThin = 66;74const titleHeightFat = 85;75const rowHeight = 52;76const pickerContainerHeight = Platform.select({ android: rowHeight * 5, ios: 220 });77const buttonHeight = 50;78const { width, height } = Dimensions.get('window');79const modalWidth = width - margin * 2;80// 选择器样式,固定81const pickerInnerStyle = {82 lineColor: Styles.common.hairlineColor,83 textColor: '#666666',84 fontSize: 15,85 selectTextColor: "#333333",86 selectFontSize: 20,87 unitTextColor: '#333333',88 unitFontSize: 10,89 rowHeight,90 selectBgColor: "#f3f3f3"91}92const months = constructArray(12, 1, 0);93const days = constructArray(31, 1, 0);94const hours24 = constructArray(24, 1, 1);95const timeSystem = [strings.am, strings.pm];96const hours12 = hours24.slice(1, 13);97const minutes = constructArray(60, 1, 1);98const singleDataSource = {99 [SINGLE_TYPE.MONTH]: months,100 [SINGLE_TYPE.DAY]: days,101 [SINGLE_TYPE.HOUR]: constructArray(24, 1, 0),102 [SINGLE_TYPE.MINUTE]: constructArray(60, 1, 0),103 [SINGLE_TYPE.SECOND]: constructArray(60, 1, 0),104}105Object.freeze(singleDataSource);106const days31 = ['01', '03', '05', '07', '08', '10', '12'];107const days30 = ['04', '06', '09', '11'];108const defaultYearOffset = 15;109/**110 * @export111 * @author Geeook112 * @since 10021113 * @module MHDatePicker114 * @description 米家插件常用的时间选择器115 * @param {string} animationType - modal 显示动效, 参考 https://facebook.github.io/react-native/docs/0.54/modal#animationtype116 * @param {bool} visible - 是否显示 modal, 参考 https://facebook.github.io/react-native/docs/0.54/modal#visible117 * @param {string} title - 标题118 * @param {bool} showSubtitle - 是否显示副标题,副标题显示的内容固定,和`type`有关 119 * @param {string} confirmColor - 确定按钮的颜色,默认米家绿120 * @param {TYPE} type - 时间选择器类型, enum('single', 'time24', 'time12', 'date')121 * @param {SINGLE_TYPE} singleType - 单个picker时的选择器类型, enum('month', 'day', 'hour', 'minute', 'second')122 * @param {array<string>|array<number>|Date} current - 当前选中值,可传入数字数组,字符串数组,Date实例,对所有时间选择器类型有效123 * @param {array<string>|array<number>|Date} min - 最小值,可传入数字数组,字符串数组,Date实例,只对`'single'`和`'date'`类型生效。对于 date 类型,默认值:现在向前15年124 * @param {array<string>|array<number>|Date} max - 最大值,可传入数字数组,字符串数组,Date实例,只对`'single'`和`'date'`类型生效。对于 date 类型,默认值:现在向后15年125 * @param {function} onSelect - 选好之后的回调函数,返回所有picker的选中值 组成的数组 / 拼接的字符串 / 以及计算出的Date实例, 详见使用 demo126 * @param {function} onDismiss - 点击`Modal`内容外面/取消按钮/确定按钮,Modal隐藏时的回调函数127 */128export default class MHDatePicker extends React.Component {129 static propTypes = {130 animationType: PropTypes.string,131 visible: PropTypes.bool,132 title: PropTypes.string,133 showSubtitle: PropTypes.bool,134 confirmColor: PropTypes.string,135 type: PropTypes.oneOf([TYPE.DATE, TYPE.SINGLE, TYPE.TIME12, TYPE.TIME24]),136 singleType: PropTypes.oneOf([137 SINGLE_TYPE.MONTH,138 SINGLE_TYPE.DAY,139 SINGLE_TYPE.HOUR,140 SINGLE_TYPE.MINUTE,141 SINGLE_TYPE.SECOND142 ]),143 current: PropTypes.oneOfType([144 PropTypes.arrayOf(PropTypes.string),145 PropTypes.arrayOf(PropTypes.number),146 PropTypes.instanceOf(Date)147 ]),148 min: PropTypes.oneOfType([149 PropTypes.arrayOf(PropTypes.string),150 PropTypes.arrayOf(PropTypes.number),151 PropTypes.instanceOf(Date)152 ]),153 max: PropTypes.oneOfType([154 PropTypes.arrayOf(PropTypes.string),155 PropTypes.arrayOf(PropTypes.number),156 PropTypes.instanceOf(Date)157 ]),158 onSelect: PropTypes.func,159 onDismiss: PropTypes.func,160 }161 static defaultProps = {162 animationType: 'fade',163 visible: false,164 title: '开启时间',165 showSubtitle: true,166 confirmColor: Styles.common.MHGreen,167 type: TYPE.TIME24,168 singleType: SINGLE_TYPE.MINUTE,169 onSelect: obj => console.log(obj),170 }171 /**172 * @description 时间选择器类型173 * @enum {string}174 */175 static TYPE = TYPE;176 /**177 * @description 单个picker时选择器的类型,也就是显示的单位178 * @enum {string}179 */180 static SINGLE_TYPE = SINGLE_TYPE;181 constructor(props, context) {182 super(props, context);183 const { currentArray, dataSourceArray } = this.init(props);184 const subtitle = this.getSubtitle(currentArray);185 this.state = {186 visible: this.props.visible,187 dataSourceArray, // 待显示的数据源数组188 currentArray, // 当前选中值数组189 subtitle,190 };191 }192 /**193 * 根据时间选择器类型、app 语言和初始值数组显示不同模板的副标题文案194 * @param {*} arr 195 */196 getSubtitle(arr) {197 if (this.props.type === TYPE.SINGLE) {198 const count = parseInt(arr[0]);199 const unit = count > 1 ? strings[this.props.singleType + 's'] : strings[this.props.singleType]; // 英文单复数单位200 return formatString(strings.singleSubTitle, count, unit);201 }202 return formatString({203 [TYPE.DATE]: strings.dateSubTitle,204 [TYPE.TIME24]: strings.time24SubTitle,205 [TYPE.TIME12]: strings.time12SubTitle,206 }[this.props.type], ...arr);207 }208 /**209 * 根据类型将 Date 实例或者 Array<number> 转换成 ['','','']形式210 * @param {*} cur 211 * @param {string} type 212 */213 convert(cur) {214 const { type } = this.props;215 if (cur instanceof Date) {216 switch (type) {217 case TYPE.DATE:218 return this.convert([cur.getFullYear(), cur.getMonth() + 1, cur.getDate()]);219 case TYPE.TIME24:220 return this.convert([cur.getHours(), cur.getMinutes()]);221 case TYPE.TIME12:222 return this.convertTo12([cur.getHours(), cur.getMinutes()]);223 case TYPE.SINGLE:224 return ['01'];225 default:226 return ['01'];227 }228 }229 else if (cur instanceof Array) {230 switch (type) {231 case TYPE.DATE:232 return cur.slice(0, 3).map((v, i) => i === 0 ? ('' + v) : (('0' + v).slice(-2)));233 case TYPE.TIME24:234 return cur.slice(0, 2).map(v => ('0' + v).slice(-2));235 case TYPE.TIME12:236 return this.convertTo12(cur);237 case TYPE.SINGLE:238 return cur.slice(0, 1).map(v => ('0' + v).slice(-2));239 default:240 return ['01'];241 }242 }243 // 异常处理1244 else if (typeof cur === 'string'245 || typeof cur === 'number') {246 return [cur + ''];247 }248 // 异常处理2249 else {250 return ['01'];251 }252 }253 /**254 * 将24小时制的数组转换成12小时制的数组255 * @param {Array} arr 256 */257 convertTo12(arr) {258 if (arr.length === 2) {259 let newArr = arr.map(v => parseInt(v));260 if (newArr.every(v => Number.isInteger)) {261 let res;262 if (newArr[0] === 0) {263 res = [strings.am, 12, newArr[1]];264 }265 else {266 const timeSystem = newArr[0] > 11 ? strings.pm : strings.am; // 下午 12:34267 const hour = newArr[0] > 12 ? (newArr[0] - 12) + '' : newArr[0] + '';268 const minute = newArr[1] + '';269 res = [timeSystem, hour, minute];270 }271 return res.map((v, i) => i > 0 ? ('0' + v).slice(-2) : v);272 }273 }274 return this.convert(new Date());275 }276 /**277 * 截取部分数组278 * @param {array} arr 279 * @param {*} head 280 * @param {*} tail 281 */282 slice(arr, head, tail) {283 if (head === undefined && tail === undefined) return arr;284 const index = arr.indexOf(('0' + head).slice(-2)) || 0;285 const lastIndex = arr.lastIndexOf(('0' + tail).slice(-2)) || arr.length - 1;286 return arr.slice(index, lastIndex + 1);287 }288 /**289 * 计算出年份的范围290 * @param {*} min 291 * @param {*} max 292 */293 getYears(min, max) {294 this.min = this.convert(min); //留一份滚动比较时候用295 this.max = this.convert(max);296 const minY = Number.parseInt(this.min[0]);297 const maxY = Number.parseInt(this.max[0]);298 return this.generateArray(minY, maxY);299 }300 /**301 * 根据极值生成步长为1的数组,并转换成字符串302 * @param {number} min 303 * @param {number} max 304 */305 generateArray(min, max) {306 if (min > max) {307 console.warn('max < min');308 return [];309 }310 return Array.from({ length: max - min + 1 }, (v, i) => i + min).map(v => v + '');311 }312 /**313 * 初始化数据,包括每个picker的范围和选中值314 */315 init(props) {316 const { type, singleType, current, min, max } = props;317 const currentArray = this.convert(current || new Date());318 switch (type) {319 case TYPE.DATE:320 const yearNow = new Date().getFullYear();321 const minDefault = new Date();322 minDefault.setFullYear(yearNow - defaultYearOffset); // Date 模式下,如果没 min,就往回 defaultYearOffset 年323 const maxDefault = new Date();324 maxDefault.setFullYear(yearNow + defaultYearOffset); // 如果没 max,就往后 defaultYearOffset 年325 const years = this.getYears(min || minDefault, max || maxDefault);326 const dataSourceArray = [years, months, days];327 this.updateDays(currentArray, dataSourceArray);328 this.unitArray = [strings.yearUnit, strings.monthUnit, strings.dayUnit];329 return {330 currentArray,331 dataSourceArray,332 }333 case TYPE.TIME24:334 this.unitArray = [strings.hourUnit, strings.minuteUnit];335 return {336 currentArray,337 dataSourceArray: [hours24, minutes],338 }339 case TYPE.TIME12:340 this.unitArray = ['', strings.hourUnit, strings.minuteUnit];341 return {342 currentArray,343 dataSourceArray: [timeSystem, hours12, minutes],344 }345 case TYPE.SINGLE:346 default:347 this.unitArray = [strings[singleType + 'Unit']];348 return {349 currentArray,350 dataSourceArray: [this.slice(singleDataSource[singleType], min, max)],351 }352 }353 }354 componentWillReceiveProps(newProps) {355 if (newProps.visible !== this.state.visible) {356 this.setState({ visible: newProps.visible });357 }358 if (newProps.current === undefined359 || newProps.current !== this.props.current) {360 const currentArray = this.convert(newProps.current || new Date());361 this.setState({362 currentArray,363 subtitle: this.getSubtitle(currentArray)364 });365 }366 }367 /**368 * 标题部分369 */370 renderTitle() {371 const height = {372 height: this.props.showSubtitle ? titleHeightFat : titleHeightThin373 }374 return (375 <View style={[styles.titleContainer, height]}>376 <Text377 numberOfLines={1}378 style={[Styles.common.title, styles.title]}379 >380 {this.props.title || ''}381 </Text>382 {this.props.showSubtitle383 ? <Text384 numberOfLines={1}385 style={styles.subtitle}386 >387 {this.state.subtitle}388 </Text>389 : null390 }391 </View>392 )393 }394 /**395 * picker 部分396 */397 renderContent() {398 const { currentArray, dataSourceArray } = this.state;399 const length = currentArray.length;400 const actualWidth = modalWidth - (length - 1) * StyleSheet.hairlineWidth; // 去掉分割线的真实宽度401 const normalWidth = actualWidth / length; // 均分宽度402 const yearWidth = normalWidth + 10; // 日期选择器的年份picker宽度稍微大一点403 const monthWidth = (actualWidth - yearWidth) / 2;404 return (405 <View style={styles.pickerContainer}>406 {dataSourceArray.map((dataSource, index) => {407 let style = { width: normalWidth };408 if (this.props.type === TYPE.DATE) {409 if (index === 0) style = { width: yearWidth };410 else style = { width: monthWidth };411 }412 return (413 <View style={[{ flexDirection: 'row' }, style]}>414 <StringSpinner415 key={index + this.unitArray[index]}416 style={style}417 unit={this.unitArray[index]}418 dataSource={dataSource}419 defaultValue={currentArray[index]}420 pickerInnerStyle={pickerInnerStyle}421 onValueChanged={data => this._onValueChanged(index, data)}422 />423 {index < length - 1424 ? <Separator type='column' style={{ height: pickerContainerHeight }} />425 : null426 }427 </View>428 )429 })}430 </View>431 )432 }433 /**434 * 底部按钮435 */436 renderButton() {437 return (438 <View style={styles.buttons}>439 <TouchableHighlight440 style={[styles.button, { borderBottomLeftRadius: borderRadius }]}441 onPress={_ => this.dismiss()}442 underlayColor='rgba(0,0,0,.05)'443 >444 <Text style={styles.buttonText}>445 {strings.cancel}446 </Text>447 </TouchableHighlight>448 <Separator type='column' style={{ height: buttonHeight }} />449 <TouchableHighlight450 style={[styles.button, { borderBottomRightRadius: borderRadius }]}451 onPress={_ => this.confirm()}452 underlayColor='rgba(0,0,0,.05)'453 >454 <Text style={[styles.buttonText, { color: this.props.confirmColor }]}>455 {strings.ok}456 </Text>457 </TouchableHighlight>458 </View>459 )460 }461 render() {462 return (463 <Modal464 animationType={this.props.animationType}465 transparent={true}466 visible={this.state.visible}467 onRequestClose={_ => this.dismiss()}468 >469 <View style={styles.background}>470 <TouchableWithoutFeedback471 onPress={_ => this.dismiss()}472 >473 <View style={{ width, height }} />474 </TouchableWithoutFeedback>475 <View style={styles.modal}>476 {this.renderTitle()}477 <Separator />478 {this.renderContent()}479 <Separator />480 {this.renderButton()}481 </View>482 </View>483 </Modal>484 );485 }486 /**487 * 是否是闰年488 * @param {number} y 489 */490 isLeapYear(y) {491 return ((y % 4 === 0 && y % 100 !== 0) || (y % 400 === 0 && y % 3200 !== 0));492 }493 /**494 * 比较`Date`时间数组的时间前后 ['2017','06','01'] > ['2017','05','31']495 * @param {array} arrA 496 * @param {array} arrB 497 */498 compareDateArray(arrA, arrB) {499 return arrA.join('') - arrB.join('');500 }501 /**502 * 计算当前年份和月份下的天数503 * @param {array} newCurrentArray 504 * @param {array<array>} newDataSourceArray 505 */506 updateDays(newCurrentArray, newDataSourceArray) {507 const [year, month, day] = newCurrentArray;508 if (days31.includes(month)) {509 newDataSourceArray[2] = days;510 }511 else if (days30.includes(month)) {512 newDataSourceArray[2] = days.slice(0, 30);513 }514 else {515 // 闰年2月29天, 平年28天516 if (this.isLeapYear(parseInt(year))) {517 newDataSourceArray[2] = days.slice(0, 29);518 }519 else {520 newDataSourceArray[2] = days.slice(0, 28);521 }522 }523 // 5月31日 -> 6月30日524 if (!newDataSourceArray[2].includes(day)) {525 newCurrentArray[2] = newDataSourceArray[2][newDataSourceArray[2].length - 1];526 }527 }528 /**529 * Picker 滚动回调530 * @param {number} index 531 * @param {object} data 532 */533 _onValueChanged(index, data) {534 let newCurrentArray = [...this.state.currentArray];535 newCurrentArray[index] = data.newValue;536 let newDataSourceArray = [...this.state.dataSourceArray];537 this.setState({538 currentArray: newCurrentArray,539 subtitle: this.getSubtitle(newCurrentArray)540 }, _ => {541 if (this.props.type === TYPE.DATE) {542 let needUpdate = false;543 // 判断是否越界544 if (this.compareDateArray(newCurrentArray, this.max) > 0) {545 newCurrentArray = this.max;546 needUpdate = true;547 }548 if (this.compareDateArray(newCurrentArray, this.min) < 0) {549 newCurrentArray = this.min;550 needUpdate = true;551 }552 this.updateDays(newCurrentArray, newDataSourceArray);553 if (newDataSourceArray[2].length !== this.state.dataSourceArray[2].length) {554 needUpdate = true;555 }556 needUpdate && this.setState({557 subtitle: this.getSubtitle(newCurrentArray),558 currentArray: newCurrentArray,559 dataSourceArray: newDataSourceArray,560 });561 }562 });563 }564 /**565 * 隐藏 Modal566 */567 dismiss() {568 this.setState({ visible: false });569 this.props.onDismiss && this.props.onDismiss();570 }571 /**572 * 把时间数组转成 `Date` 实例573 * ['2019','06','03'] -> new Date()574 * ['15','36'] -> new Date()575 * ['下午','03','36'] -> new Date()576 */577 array2Date() {578 const { currentArray } = this.state;579 let date = new Date();580 switch (this.props.type) {581 case TYPE.DATE:582 date.setFullYear(currentArray[0]);583 date.setMonth(parseInt(currentArray[1]) - 1);584 date.setDate(parseInt(currentArray[2]));585 break;586 case TYPE.TIME24:587 date.setHours(currentArray[0]);588 date.setMinutes(currentArray[1]);589 break;590 case TYPE.TIME12:591 let hour = parseInt(currentArray[1]);592 if (currentArray[0] === strings.am) {593 hour = hour === 12 ? 0 : hour;594 }595 else {596 hour = hour < 12 ? hour + 12 : hour;597 }598 date.setHours(hour);599 date.setMinutes(currentArray[2]);600 break;601 case TYPE.SINGLE:602 default:603 return null;604 }605 return date;606 }607 confirm() {608 if (this.props.onSelect) {609 this.props.onSelect({610 rawArray: this.state.currentArray,611 rawString: this.state.subtitle,612 date: this.array2Date()613 });614 }615 this.dismiss();616 }617}618const styles = StyleSheet.create({619 background: {620 flex: 1,621 backgroundColor: screenBackgroundColor622 },623 modal: {624 position: 'absolute',625 bottom: 20,626 width: modalWidth,627 marginHorizontal: margin,628 backgroundColor: '#fff',629 borderRadius,630 },631 titleContainer: {632 justifyContent: 'center',633 alignItems: 'center',634 },635 title: {636 fontFamily: 'D-DINCondensed-Bold',637 },638 subtitle: {639 width: modalWidth,640 textAlign: 'center',641 fontSize: 13,642 color: '#666'643 },644 pickerContainer: {645 flexDirection: 'row',646 height: pickerContainerHeight,647 justifyContent: 'space-between'648 },649 buttons: {650 height: buttonHeight,651 flexDirection: 'row',652 backgroundColor: 'transparent',653 justifyContent: 'space-between'654 },655 button: {656 flex: 1,657 backgroundColor: 'transparent',658 justifyContent: 'center',659 alignItems: 'center',660 },661 buttonText: {662 fontSize: 14,663 lineHeight: 19,664 color: '#666',665 fontFamily: 'D-DINCondensed-Bold' // TODO: 英文字体,中文加粗效果666 }...

Full Screen

Full Screen

create_assessment.js

Source:create_assessment.js Github

copy

Full Screen

1function validation()2{3 var assessment_name = document.getElementById("question_bank_name");4 var name_msg = document.getElementById("name_msg");5 var topic_name = document.getElementById("topic");6 var topic_name_msg = document.getElementById("topic_name_msg");7 var single_type = document.getElementById("single_type");8 var multiple_type = document.getElementById("multiple_type");9 var radio_manual = document.getElementById("manual_type");10 var radio_excel = document.getElementById("excel_type");11 var radio_prev = document.getElementById("previous_type");12 var radio_check_msg = document.getElementById("radio_check_msg");13 var single_prev_assessments = document.getElementsByName("radio_check");14 var multiple_prev_assessments = document.getElementsByName("checkbox_check");15 var checked = 0;16 if (assessment_name.value.split(' ').join('') == "") {17 topic_name_msg.style.display = "none";18 name_msg.style.display = "block";19 name_msg.style.color = "red";20 return false;21 }22 else if(radio_prev.checked == true) {23 if(single_type != null && single_type.checked == true){24 for(var i=1;i<=single_prev_assessments.length;i++){25 var single_radio = document.getElementById("single_"+i);26 if(single_radio.checked == true){27 checked = 1;28 break;29 }30 }31 } else if(multiple_type != null && multiple_type.checked == true){32 for(var j=1;j<=multiple_prev_assessments.length;j++){33 var multiple_checkbox = document.getElementById("checkbox_check_"+j);34 if(multiple_checkbox.checked == true){35 checked = 1;36 break;37 }38 }39 }40 if(checked == 0){41 return false;42 } else {43 assessment_name.disabled = false;44 topic_name.disabled = false;45 return true;46 }47 }48 else if(radio_manual.checked == false && radio_excel.checked == false && radio_prev.checked == false) {49 name_msg.style.display = "none";50 topic_name_msg.style.display = "none";51 radio_check_msg.style.display = "block";52 return false;53 }54 else if(multiple_type.checked == true && radio_prev.checked == false && topic_name.value.split(' ').join('') == "") {55 name_msg.style.display = "none";56 topic_name_msg.style.display = "block";57 topic_name_msg.style.color = "red";58 return false;59 } 60 else {61 topic_name_msg.style.display = "none";62 name_msg.style.display = "none";63 radio_check_msg.style.display = "none";64 assessment_name.disabled = false;65 topic_name.disabled = false;66 return true;67 // return false;68 }69}70function textCounter(field,cntfield,maxlimit) {71 if (field.value.length > maxlimit) // if too long...trim it!72 field.value = field.value.substring(0, maxlimit);73 // otherwise, update 'characters left' counter74 else75 cntfield.value = maxlimit - field.value.length;76}77function take_topic_name()78{79 var single_type = document.getElementById("single_type");80 var multiple_type = document.getElementById("multiple_type");81 var radio_prev = document.getElementById("previous_type");82 var field = document.getElementById("topic_name");83 if(multiple_type.checked == true)84 {85 if(radio_prev.checked == true) {86 show_previous_assmts("previous_questions")87 } else {88 field.style.display = "block";89 } 90 }91 if(single_type.checked == true)92 {93 if(radio_prev.checked == true) {94 show_previous_assmts("previous_questions")95 }96 field.style.display = "none";97 } 98}99function total_no_of_checks(j)100{101 upload_bar = document.getElementById("progress_bar");102 upload_bar.style.display = "block";103 var total_prev_qb_checked = document.getElementById('total_prev_qb_checked');104 for(var i=1;i<=j;i++)105 {106 var chk_box = document.getElementById('checkbox_check_'+i);107 if(chk_box.checked == true)108 {109 total_prev_qb_checked.value = total_prev_qb_checked.value + "," + chk_box.value;110 }111 }112}113function show_previous_assmts(val)114{115 var single_type = document.getElementById("single_type");116 var multiple_type = document.getElementById("multiple_type");117 var topic = document.getElementById("topic");118 var previous_assessments_for_single = document.getElementById('previous_assessments_for_single');119 var previous_assessments_for_multiple = document.getElementById('previous_assessments_for_multiple');120 var field = document.getElementById("topic_name");121 var upload_excel = document.getElementById('upload_excel');122 if(val == "previous_questions" && single_type != null && single_type.checked == true)123 {124 field.style.display = "none";125 previous_assessments_for_single.style.display = "block";126 previous_assessments_for_multiple.style.display = "none";127 upload_excel.style.display = "none";128 }129 else if(val == "previous_questions" && multiple_type != null && multiple_type.checked == true)130 {131 field.style.display = "none";132 previous_assessments_for_multiple.style.display = "block";133 previous_assessments_for_single.style.display = "none";134 topic.disabled = true;135 topic.style.color = "gray";136 upload_excel.style.display = "none";137 }138 else if(val == "excelsheet")139 {140 upload_excel.style.display = "block";141 previous_assessments_for_multiple.style.display = "none";142 previous_assessments_for_single.style.display = "none";143 }144 else if(val == "manual" && single_type != null && single_type.checked == true)145 {146 field.style.display = "none";147 upload_excel.style.display = "none";148 previous_assessments_for_multiple.style.display = "none";149 previous_assessments_for_single.style.display = "none";150 }151 else152 {153 field.style.display = "block";154 previous_assessments_for_single.style.display = "none";155 previous_assessments_for_multiple.style.display = "none";156 topic.disabled = false;157 upload_excel.style.display = "none";158 }159}160function show_browse(val,div)161{162 var div = document.getElementById(div);163 if(val.checked == true && val.value=="excelsheet")164 {165 div.style.display = "block";166 }167 else168 {169 div.style.display = "none";170 remove_add.style.display = "block";171 }172}173function none_checked()174{175 var myoption = -1;176 var i;177 for (i=document.myform.assessment_type.length-1; i > -1; i--)178 {179 if (document.myform.assessment_type[i].checked)180 {181 myoption = i;182 i = -1;183 }184 }185 if (myoption == -1)186 {187 return false;188 }189 return true;190}191function form_validate()192{193 if(document.getElementById('question_bank_name').value.split(' ').join('') == "")194 {195 document.getElementById('question_bank_name_error').style.display="block";196 return false;197 }198 else if(document.getElementById('multiple_type').checked == true)199 {200 if(document.getElementById('topic').value.split(' ').join('') == "")201 {202 document.getElementById('topic_error').style.display="block";203 return false;204 }205 }206 else if(none_checked() == false)207 {208 return false;209 }210}211function set_style(set,set_none1,set_none2,set_none3,set_none4){212 var set_div = document.getElementById(set);213 var set_none1_div = document.getElementById(set_none1);214 var set_none2_div = document.getElementById(set_none2);215 var set_none3_div = document.getElementById(set_none3);216 var set_none4_div = document.getElementById(set_none4);217 set_div.style.display="block";218 set_div.style.color="red";219 set_div.setAttribute("style", "display: block; color: red; margin:5px 0px 0px 10px;float:left; font-size: 12px;");220 set_none1_div.style.display="none";221 set_none2_div.style.display="none";222 set_none3_div.style.display="none";223 set_none4_div.style.display="none";224}225//Displays messages on validation226function validate(ctr1,ctr2) {227 if((document.getElementById(ctr1).value.split(' ').join('') == "") ||228 (document.getElementById(ctr1).value.split(' ').join('') == "0"))229 {230 document.getElementById(ctr2).style.display = "block";231 return false;232 } else {233 document.getElementById(ctr2).style.display = "none";234 return true;235 }...

Full Screen

Full Screen

records.js

Source:records.js Github

copy

Full Screen

1export const SIMPLE_RECORD = {2 id: 'SIMPLE_RECORD_ID',3 type: 'SIMPLE_RECORD_TYPE',4 attributes: {5 a: 'SIMPLE_RECORD_ATTR_A',6 b: 'SIMPLE_RECORD_ATTR_B',7 },8}9export const RECORD_WITH_RELATIONSHIPS = {10 id: 'RECORD_WITH_RELATIONSHIPS_ID',11 type: 'RECORD_WITH_RELATIONSHIPS_TYPE',12 attributes: {13 a: 'RECORD_WITH_RELATIONSHIPS_ATTR_A',14 b: 'RECORD_WITH_RELATIONSHIPS_ATTR_B',15 RECORD_WITH_RELATIONSHIPS_REL_NULL: 'attribute with relationship name',16 RECORD_WITH_RELATIONSHIPS_REL_SINGLE: 'attribute with relationship name',17 RECORD_WITH_RELATIONSHIPS_REL_MULTIPLE: 'attribute with relationship name',18 },19 relationships: {20 RECORD_WITH_RELATIONSHIPS_REL_NULL: {21 data: null,22 },23 RECORD_WITH_RELATIONSHIPS_REL_SINGLE: {24 data: {25 id: 'SINGLE_ID',26 type: 'SINGLE_TYPE',27 },28 meta: { META_SINGLE: 'META_SINGLE' },29 },30 RECORD_WITH_RELATIONSHIPS_REL_MULTIPLE: {31 data: [{32 id: 'ITEM_1_ID',33 type: 'ITEM_1_TYPE',34 }, {35 id: 'ITEM_2_ID',36 type: 'ITEM_2_TYPE',37 }],38 meta: { META_MULTIPLE: 'META_MULTIPLE' },39 },40 },41}42export const RECORD_WITH_RELATIONSHIPS_NORMALIZED = {43 __type: 'RECORD_WITH_RELATIONSHIPS_TYPE',44 id: 'RECORD_WITH_RELATIONSHIPS_ID',45 a: 'RECORD_WITH_RELATIONSHIPS_ATTR_A',46 b: 'RECORD_WITH_RELATIONSHIPS_ATTR_B',47 RECORD_WITH_RELATIONSHIPS_REL_NULL: null,48 RECORD_WITH_RELATIONSHIPS_REL_SINGLE: {49 __type: 'SINGLE_TYPE',50 id: 'SINGLE_ID',51 SINGLE_TEST: 'test',52 },53 RECORD_WITH_RELATIONSHIPS_REL_MULTIPLE: [54 {55 __type: 'ITEM_1_TYPE',56 id: 'ITEM_1_ID',57 ITEM_1_TEST: 'test',58 },59 {60 __type: 'ITEM_2_TYPE',61 id: 'ITEM_2_ID',62 ITEM_2_TEST: 'test',63 },64 ],65}66export const RECORD_WITH_RELATIONSHIPS_UPDATED = {67 id: 'RECORD_WITH_RELATIONSHIPS_ID',68 type: 'RECORD_WITH_RELATIONSHIPS_TYPE',69 attributes: {70 b: 'RECORD_WITH_RELATIONSHIPS_ATTR_B_UPDATED',71 c: 'RECORD_WITH_RELATIONSHIPS_ATTR_C_UPDATED',72 RECORD_WITH_RELATIONSHIPS_REL_NULL: 'attribute with relationship name (updated)',73 RECORD_WITH_RELATIONSHIPS_REL_SINGLE: 'attribute with relationship name (updated)',74 RECORD_WITH_RELATIONSHIPS_REL_MULTIPLE: 'attribute with relationship name (updated)',75 },76 relationships: {77 RECORD_WITH_RELATIONSHIPS_REL_NULL: {78 data: {79 id: 'SINGLE_ID',80 type: 'SINGLE_TYPE',81 },82 meta: { META_NULL: 'META_NULL' },83 },84 RECORD_WITH_RELATIONSHIPS_REL_SINGLE: {85 data: null,86 meta: { META_SINGLE_UPDATED: 'META_SINGLE_UPDATED' },87 },88 },89}90export const RECORD_WITH_RELATIONSHIPS_UPDATED_NORMALIZED = {91 __type: 'RECORD_WITH_RELATIONSHIPS_TYPE',92 id: 'RECORD_WITH_RELATIONSHIPS_ID',93 a: 'RECORD_WITH_RELATIONSHIPS_ATTR_A',94 b: 'RECORD_WITH_RELATIONSHIPS_ATTR_B_UPDATED',95 c: 'RECORD_WITH_RELATIONSHIPS_ATTR_C_UPDATED',96 RECORD_WITH_RELATIONSHIPS_REL_NULL: {97 __type: 'SINGLE_TYPE',98 id: 'SINGLE_ID',99 SINGLE_TEST: 'test',100 },101 RECORD_WITH_RELATIONSHIPS_REL_SINGLE: null,102 RECORD_WITH_RELATIONSHIPS_REL_MULTIPLE: [103 {104 __type: 'ITEM_1_TYPE',105 id: 'ITEM_1_ID',106 ITEM_1_TEST: 'test',107 },108 {109 __type: 'ITEM_2_TYPE',110 id: 'ITEM_2_ID',111 ITEM_2_TEST: 'test',112 },113 ],114}115export const RECORD_WITH_RELATIONSHIPS_RELATIONS = [116 {117 id: 'SINGLE_ID',118 type: 'SINGLE_TYPE',119 attributes: {120 SINGLE_TEST: 'test',121 },122 },123 {124 id: 'ITEM_1_ID',125 type: 'ITEM_1_TYPE',126 attributes: {127 ITEM_1_TEST: 'test',128 },129 },130 {131 id: 'ITEM_2_ID',132 type: 'ITEM_2_TYPE',133 attributes: {134 ITEM_2_TEST: 'test',135 },136 },...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.page('Albert Einstein').then(function(page) {3 return page.single_type('infobox');4}).then(function(infobox) {5 console.log(infobox);6});7var wptools = require('wptools');8wptools.page('Albert Einstein').then(function(page) {9 return page.single_type('infobox');10}).then(function(infobox) {11 console.log(infobox);12});13var wptools = require('wptools');14wptools.page('Albert Einstein').then(function(page) {15 return page.single_type('infobox');16}).then(function(infobox) {17 console.log(infobox);18});19var wptools = require('wptools');20wptools.page('Albert Einstein').then(function(page) {21 return page.single_type('infobox');22}).then(function(infobox) {23 console.log(infobox);24});25var wptools = require('wptools');26wptools.page('Albert Einstein').then(function(page) {27 return page.single_type('infobox');28}).then(function(infobox) {29 console.log(infobox);30});31var wptools = require('wptools');32wptools.page('Albert Einstein').then(function(page) {33 return page.single_type('infobox');34}).then(function(infobox) {35 console.log(infobox);36});37var wptools = require('wptools');38wptools.page('Albert Einstein').then(function(page) {39 return page.single_type('infobox');40}).then(function(infobox) {41 console.log(infobox);42});43var wptools = require('wptools');44wptools.page('Albert Einstein').then(function(page) {45 return page.single_type('infobox');46}).then(function(infobox) {47 console.log(infobox);48});49var wptools = require('wpt

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var fs = require('fs');3var util = require('util');4var test = wpt('www.webpagetest.org');5var location = 'Dulles_MotoG4:Chrome';6var runs = 3;7var firstViewOnly = true;8var video = true;9var pollResults = 5;10var timeout = 300;11var fvonly = true;12var requests = true;13var timeline = true;14var waterfall = true;15var breakDown = true;16var connectionView = true;17var data = {18};19test.runTest(data, function (err, result) {20 if (err) {21 console.log(err);22 }23 else {24 console.log(result);25 fs.writeFile('result.json', util.inspect(result), function (err) {26 if (err) {27 return console.error(err);28 }29 console.log('Data written successfully!');30 });31 }32});33var wpt = require('webpagetest');34var fs = require('fs');35var util = require('util');36var test = wpt('www.webpagetest.org');37var location = 'Dulles_MotoG4:Chrome';38var runs = 3;39var firstViewOnly = true;40var video = true;41var pollResults = 5;42var timeout = 300;43var fvonly = true;44var requests = true;45var timeline = true;46var waterfall = true;47var breakDown = true;48var connectionView = true;49var data = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2 if (error) {3 console.log(error);4 } else {5 console.log(data);6 }7});8var wpt = require('./wpt.js');9 if (error) {10 console.log(error);11 } else {12 console.log(data);13 }14});15var wpt = require('./wpt.js');16 if (error) {17 console.log(error);18 } else {19 console.log(data);20 }21});22var wpt = require('./wpt.js');23 if (error) {24 console.log(error);25 } else {26 console.log(data);27 }28});29var wpt = require('./wpt.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1d0e7d2e0b2f7b9c9b9f7d0c6c1d1c19');3var location = 'Dulles:Chrome';4var options = {5};6wpt.runTest(url, options, function(err, data) {7 if (err) return console.log(err);8 console.log(data);9});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful