123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- var template_id,
- template_info;
- mui.init();
- mui.plusReady(function(){
- var self = plus.webview.currentWebview();
- template_id = self.template_id;
- template_info = self.info;
- getTemplateLabel();
- bindEvents();
- sqlite.open('MyData2','1.0','My Database', 1024*100);
- createTemplateTable();
- });
- function getTemplateLabel(){
- var url = "/doctor/questionnaire/getTemplateLabel";
- sendGet(url, {}, null, function(res){
- if(res.status == 200){
- if(res.data.length == 0){
- $(".header-link").hide();
- }else{
- var html = template("label_tmp", {list: res.data});
- $("#labels").append(html);
- }
- if(template_info){
- fillInfo();
- }
- }else{
- $(".header-link").hide();
- }
- }, true);
- }
- function fillInfo(){
- $("#survey_name").val(template_info.title);
- $("#survey_summary").val(template_info.comment);
- for(i=0; i< template_info.label.length; i++){
- var item = template_info.label[i];
- $(".flag[data-text="+item+"]").addClass("active");
- }
- }
- function bindEvents(){
- $("#labels").on('click', '.flag',function(){
- var classList = this.classList;
- if(classList.contains("active")){
- classList.remove("active");
- }else{
- classList.add("active");
- }
- });
-
- $("#next_btn").on('click', function(){
- var survey_name = $("#survey_name").val(),
- survey_summary = $("#survey_summary").val(),
- $flags = $(".flag"),
- len = $flags.length,
- label = [];
- errMsg = "";
- if($.trim(survey_name).length == 0){
- errMsg += "请填写问卷名称";
- }
- if($.trim(survey_summary).length == 0){
- errMsg += "<br/>请填写问卷说明";
- }
-
- var selected = 0;
- for(i=0; i<len; i++){
- var item = $flags[i];
- if(item.classList.contains("active")){
- selected ++;
- label.push({id: $(item).attr("data-val"), value: $(item).text()});
- }
- }
- if(selected == 0){
- errMsg += "<br/>请选择问卷标签";
- }
-
- if(errMsg.length >0){
- dialog({
- content:errMsg,
- contentType: "tipsbox",
- skin: "bk-popup",
- closeTime: 2000
- }).showModal();
- }else{
- sqlite.executeSql(
- 'insert into template(name, comment, label) VALUES(?,?,?)',
- [survey_name, survey_summary, JSON.stringify(label)],
- function(tx, rs){
- console.log(rs);
- var table_tp_id = rs.insertId;
- if(template_id){
- openWebview("preview.html",{
- table_tp_id: table_tp_id,
- code: template_id,
- info: {
- name: survey_name,
- comment: survey_summary,
- label: label
- }
- });
- }else{
- openWebview("edit_questions.html",{
- code: template_id,
- table_tp_id: table_tp_id,
- info: {
- name: survey_name,
- comment: survey_summary,
- label: label
- }
- });
- }
- }, function(tx, rs){
- console.log(rs)
- });
- }
- });
- }
- function createTemplateTable(){
- sqlite.executeSql("create table if not exists template "+
- "(id INTEGER PRIMARY KEY, name TEXT, comment TEXT, label TEXT)",[],
- function(tx, rs){
- console.log("tempale 表创建成功");
- },
- function(tx, rs){
- console.error(rs)
- alert("创建缓存空间失败!");
- }
- )
- }
|