0

私はGoogleAppsScriptの初心者です。他の関数のflextableのタグから値を取得したい。以前、doGet()関数でsetTag( "init")を使用してタグを開始しましたが、getTag()を呼び出したとき、ここにコードはありません(空白)

var SPREADSHEET_ID = "xxx";

function doGet(){
  var app = UiApp.createApplication().setTitle('Request For Leaving');
  var panel = app.createVerticalPanel();
  var grid = app.createGrid(4, 4).setId('request');

  var employee = gsLibrary.getEmployee(SPREADSHEET_ID);

  var date1 = new Date();
  var preLabel = app.createLabel(': ').setText(': ');
  var preLabel2 = app.createLabel(': ').setText(': ');
  var preLabel3 = app.createLabel(': ').setText(': ');
  var preLabel4 = app.createLabel(': ').setText(': ');
  var preLabel5 = app.createLabel(': ').setText(': ');

  var employee = gsLibrary.getEmployee(SPREADSHEET_ID);
  var idLabel = app.createLabel('Employee ID ');
  var userIdLabel = app.createLabel(employee.employeeId).setId('userId').setTag(employee.employeeId);

  var yearLabel = app.createLabel('Year ');
  var yearDropdown = app.createListBox().setName("yearList").setId("yearList").setWidth('120px');

  var statusLabel = app.createLabel('Status ');
  var statusDropdown = app.createListBox().setName("statusList").setId("statusList").setWidth('120px');

  var searchButton = app.createButton("Search").setId("search");

  grid.setWidget(0, 0, idLabel)
    .setWidget(0, 1, preLabel5)
    .setWidget(0, 2, userIdLabel)
    .setWidget(1, 0, yearLabel)
    .setWidget(1, 1, preLabel4)
    .setWidget(1, 2, yearDropdown)
    .setWidget(1, 3, searchButton)
    .setWidget(2, 0, statusLabel)
    .setWidget(2, 1, preLabel3)
    .setWidget(2, 2, statusDropdown);

 var flexTable = app.createFlexTable()     
     .setId('myTable')
     .setTag('init')
     .setStyleAttribute('border','1px solid black')
     .setStyleAttribute("left","50px")
     .setStyleAttribute('borderCollapse','collapse')
     .setBorderWidth(1)
     .insertRow(0)
     .insertCell(0, 0).setStyleAttribute(0,0,"width","20px")
     .insertCell(0, 1).setStyleAttribute(0,1,"width","80px")
     .insertCell(0, 2).setStyleAttribute(0,2,"width","70px")
     .insertCell(0, 3).setStyleAttribute(0,3,"width","70px")
     .insertCell(0, 4).setStyleAttribute(0,4,"width","500px")
     .insertCell(0, 5).setStyleAttribute(0,5,"width","50px")
     .setText(0,0,'No. ')
     .setText(0, 1,'Leave Day(s)')
     .setText(0, 2,'Start Date')
     .setText(0, 3,'End Date')
     .setText(0, 4,'Description')
     .setText(0, 5,'Status')
     .setStyleAttribute('text-align','center').setCellPadding(10).setVisible(true);

  var searchHandler = app.createServerClickHandler('searchRequestList');   
  searchHandler.addCallbackElement(panel);   
  searchButton.addClickHandler(searchHandler);  
  setYearList(app,employee);
  setStatusList(app);

  panel.add(grid);
  panel.add(flexTable);
  app.setStyleAttribute("height","auto");
  app.add(panel);
  return app;
}

function setYearList(app,employee){
  var yearList = app.getElementById("yearList");
  var listYear=getAllYear(employee);
  var index=0;
  yearList.addItem("All Year");
  for (var i=0;i<listYear.length;i++){
    yearList.addItem(listYear[i]);
    index++;
  }

}

function getAllYear(user){
  var AllLeaveObjects = gsLibrary.getAllLeaveRequestByUser(SPREADSHEET_ID, user);
  var m_yearList=[];
  for (var i =0 ;i<AllLeaveObjects.length;i++){
   var status=true;
   var index;
   index=0;
    while (status==true && index<=m_yearList.length){
      if (gsLibrary.getYear(AllLeaveObjects[i].startDate)==m_yearList[index]){
        status =false;
     }
      index++;       
   }
    if (status==true){
      m_yearList.push(gsLibrary.getYear(AllLeaveObjects[i].startDate));

    }

  }

  m_yearList.sort();
  return m_yearList;
}

function setStatusList(app){
 var statusList = app.getElementById("statusList");
  var allStatus=getAllStatusName();
   statusList.addItem("All Status");
  for (var i=0;i<allStatus.length;i++){
    statusList.addItem(allStatus[i].status);
  }
}

function getAllStatusName(){
  var spreadsheetId = SPREADSHEET_ID;
  var sheet  = SpreadsheetApp.openById(spreadsheetId).getSheetByName("Status Request");
  var status = gsLibrary.getRowsData(sheet);  
  return status;
}

function getStatusNameByNum(num){
  var statusName;

  var allStatusName = getAllStatusName();
  for (var i =0 ;i<allStatusName.length;i++){
    if (num == allStatusName[i].statusCode){
      statusName = allStatusName[i].status;
    }
  }
  return statusName;
}

function searchRequestList(e){
    var app = UiApp.getActiveApplication();
    var employee = gsLibrary.getEmployee(SPREADSHEET_ID);
    var year=e.parameter.yearList;
    var status = e.parameter.statusList;

    fillTable(app,employee,year,status);
    return app;
}

function fill(table, LeaveRequest, index, row, tag){
  table.setText(index+1,0,index+1);
  table.setText(index+1,1,LeaveRequest[row].numberOfDays);
  table.setText(index+1,2,gsLibrary.convertDate(LeaveRequest[row].startDate));
  table.setText(index+1,3,gsLibrary.convertDate(LeaveRequest[row].endDate));
  table.setText(index+1,4,table.getTag()); //<--- this is the problem, always blank
  table.setText(index+1,5,getStatusNameByNum(LeaveRequest[row].status));
}

function setTagTable(){
  var app = UiApp.getActiveApplication();
  var table = app.getElementById("myTable");
  if(table.getTag() == 'init'){
    table.setTag() = '1';
  }
}

function fillTable(app,employee, year, status){
  setTagTable();
  var table =app.getElementById("myTable");
  var label = app.getElementById("showLabel");
  var LeaveRequest = gsLibrary.getAllLeaveRequestByUser(SPREADSHEET_ID, employee);
  var index = 0;


  if(year == "All Year" && status == "All Status"){
      for (var row = 0; row<LeaveRequest.length; row++){
        fill(table, LeaveRequest, index, row, ntag);
        index++;        
      }
  }
  else if(year == "All Year"){
      for (var row = 0; row<LeaveRequest.length; row++){
        if(getStatusNameByNum(LeaveRequest[row].status) == status){
          fill(table, LeaveRequest, index, row, ntag);
          index++;          
        }
      }
  }
  else if(status == "All Status"){
      for (var row = 0; row<LeaveRequest.length; row++){
        if(gsLibrary.getYear(LeaveRequest[row].startDate) == year){
          fill(table, LeaveRequest, index, row, ntag);
          index++;          
        }
      }
  }
  else {
      for (var row = 0; row<LeaveRequest.length; row++){
        if(gsLibrary.getYear(LeaveRequest[row].startDate) == year && getStatusNameByNum(LeaveRequest[row].status) == status){
          fill(table, LeaveRequest, index, row, ntag);
          index++;          
        }
      }
  }
}

gsLibraryは私が以前に作成したライブラリであり、問​​題はありません...ありがとうございます:D

4

1 に答える 1

0

以下に示す方法で、任意のウィジェットのタグを取得できます

function doGet(){
  ...
  var lbl = app.createLabel('Hello World').setId('lbl').setTag('tag'); 
  ...
}

function handleFunction(e){
  /* Some handler function invoked when a button is clicked etc. */
  var tag = e.parameter.lbl_tag; 
}
于 2012-07-24T05:00:45.577 に答える