Example #1
0
 private void onNameChanged(InputEvent e) {
   String value = e.getValue();
   Textbox box = (Textbox) e.getTarget();
   String lastName, firstName;
   if (box == lastNameBox) {
     lastName = value;
     firstName = firstNameBox.getValue();
   } else {
     lastName = lastNameBox.getValue();
     firstName = value;
   }
   labelBox.setValue(lastName + ", " + firstName);
 }
Example #2
0
 /**
  * *********************************************************** Search
  * ***********************************************************
  */
 @Listen("onClick = #searchBtn")
 public void search() {
   String searchTerm = searchBox.getValue();
   List<Node> nodes = nodeDao.matchByLabel("%" + searchTerm + "%");
   ListModelList<Node> nodeModel = new ListModelList<Node>(nodes);
   nodeList.setModel(nodeModel);
   nodeList.setItemRenderer(new NodeRenderer());
   footer.setLabel(nodes.size() + " nodes found.");
 }
Example #3
0
  /**
   * *********************************************************** Create
   * ***********************************************************
   */
  @SuppressWarnings("rawtypes")
  private void onNodeTypeChanged() {
    ListModelList typeModel = (ListModelList) typeBox.getModel();
    Set selections = typeModel.getSelection();
    if (selections.isEmpty()) return;
    String selection = (String) selections.iterator().next();
    logger.info("Node type set to: " + selection);

    Map<String, String> ntd = GeneralUtil.getNodeDescriptionByLabel(ntds, selection);
    String nodeType = ntd.get("type");
    if (nodeType.equals(Constants.NODE_TYPE_USER)) {
      firstNameRow.setVisible(true);
      firstNameBox.setConstraint("no empty");
      lastNameRow.setVisible(true);
      lastNameBox.setConstraint("no empty");
      midNameRow.setVisible(true);
    } else {
      firstNameRow.setVisible(false);
      firstNameBox.setConstraint("");
      lastNameRow.setVisible(false);
      lastNameBox.setConstraint("");
      midNameRow.setVisible(false);
    }
  }
Example #4
0
 /// Search Data and add to array
 @Listen("onClick = #btnsave")
 public void btnsave_Clicked(Event event) {
   int a = 0, bc = 0, closs = 0;
   for (Store e : Store.findAllStores()) {
     Textbox txtid = (Textbox) find(getPage(), "#idproduct").get(0);
     if ((Integer.parseInt(txtid.getText())) == e.getIdproduct()) {
       checksamesell(e.getNameproduct());
       if (checksame == true) {
         int oldqty = qty.get(posarray);
         int modernqty = oldqty + Integer.parseInt(idqty.getValue());
         qty.remove(posarray);
         qty.add(posarray, modernqty);
         int medernprice = e.getPrice() * modernqty;
         price.remove(posarray);
         price.add(posarray, medernprice);
         checksame = false;
         break;
       } else {
         idpro.add(Integer.parseInt(idproduct.getValue()));
         nameproduct.add(e.getNameproduct());
         qty.add(Integer.parseInt(idqty.getValue()));
         unitprice.add(e.getPrice());
         bc = e.getPrice();
         a = Integer.parseInt(idqty.getValue());
         closs = a * bc;
         price.add(closs);
         namecus.add((String) Sessions.getCurrent().getAttribute("name"));
         pointcount++;
         break;
       }
     }
   }
   Textbox txtid = (Textbox) find(getPage(), "#idproduct").get(0);
   Textbox txtqty = (Textbox) find(getPage(), "#idqty").get(0);
   txtid.setValue(null);
   txtqty.setValue(null);
   showgrid();
 }
Example #5
0
  /**
   * *************************************************** Helper methods
   * ***************************************************
   */
  private Node createNode() throws InterruptedException {
    Comboitem item = typeBox.getSelectedItem();
    if (item == null) {
      Messagebox.show("Node type is required.");
      return null;
    }

    String nodeType = GeneralUtil.getNodeDescriptionByLabel(ntds, item.getLabel()).get("type");
    String firstName = firstNameBox.getValue().trim();
    String lastName = lastNameBox.getValue().trim();
    String midName = midNameBox.getValue().trim();
    String label = labelBox.getValue().trim();
    String username;
    if (nodeType.equals(Constants.NODE_TYPE_USER)) {
      if (firstName.isEmpty()) {
        Messagebox.show("First Name is required.");
        return null;
      } else if (firstName.length() > 80) {
        Messagebox.show("First Name cannot be longer than 80.");
        return null;
      } else if (GeneralUtil.containSpecialCharacter(firstName)) {
        Messagebox.show("First Name cannot contain special characters.");
        return null;
      }

      if (lastName.isEmpty()) {
        Messagebox.show("Last Name is required.");
        return null;
      } else if (lastName.length() > 80) {
        Messagebox.show("Last Name cannot be longer than 80.");
        return null;
      } else if (GeneralUtil.containSpecialCharacter(lastName)) {
        Messagebox.show("Last Name cannot contain special characters.");
        return null;
      }

      username = firstName.replace(" ", "_") + "__" + lastName.replace(" ", "_");
    } else {
      if (label.isEmpty()) {
        Messagebox.show("Label is required.");
        return null;
      } else if (label.length() > 255) {
        Messagebox.show("Label cannot be longer than 255.");
        return null;
      }
      username = GeneralUtil.replaceSpecialCharacter(label, "_").replace(" ", "_");
    }

    if (nodeDao.findByUsername(username) != null) {
      Messagebox.show("Username: "******" has already been used.");
      return null;
    }

    Survey survey = surveyDao.findById(1L);
    Node node = new Node();
    node.setType(nodeType);
    node.setUsername(username);
    node.setLabel(label);
    if (nodeType.equals(Constants.NODE_TYPE_USER)) {
      node.setFirstName(firstName);
      node.setLastName(lastName);
      node.setMidName(midName);
    }

    String defaultPassword = survey.getAttribute(Constants.SURVEY_DEFAULT_PASSWORD);
    if (defaultPassword == null) {
      defaultPassword = "******";
    }
    if (defaultPassword.equals("rAnDoM")) {
      RandomString rs = new RandomString(8);
      defaultPassword = rs.nextString();
    }
    node.setPassword(defaultPassword);

    node.setAttribute(
        Constants.NODE_LOGIN_MODE, survey.getAttribute(Constants.SURVEY_DEFAULT_LOGIN_MODE));

    // role
    node.getRoles().add(roleDao.findByName(Constants.ROLE_USER));

    // groups
    Set<Group> groups = new HashSet<Group>();
    AbstractQuestionRelation p = (AbstractQuestionRelation) getParent();
    groups.addAll(p.getQuestion().getAvailableGroups());
    groups.add(groupDao.findByName(Constants.GROUP_ALL));

    if (nodeType.equals(Constants.NODE_TYPE_USER)) {
      groups.add(groupDao.findByName(Constants.GROUP_USER));
    } else {
      String groupName = Constants.GROUP_NODE_TYPE_PREFIX + nodeType;
      Group group = groupDao.findByName(groupName);
      if (group == null) {
        group = new Group();
        group.setName(groupName);
        groupDao.save(group);
        logger.info("created new group: " + group.getName());
      }
      groups.add(group);
    }

    node.setGroups(groups);

    // save
    nodeDao.save(node);
    logger.debug("Node created: " + username);

    return node;
  }