How to use the api.hasValue function in api

To help you get started, we’ve selected a few api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rafi16jan / rapyd-framework / client / src / components / Field.jsx View on Github external
api.globals.onchange_running = false;
    window.models.env.context.active_error && (window.models.env.context.active_error.field_map[this.props.name] = false);
    if (this.input_type && this.input_type === 'file' && value) {
      value = await api.readAsDataURL(value);
      value = value.split('base64,')[1];
    }
    if (!this.props.cellEdit) window.models.env.context.active_id[this.props.name] = value;
    else return window.models.env.context.refresh();
    await window.models.env.context.active_id._wait_promise();
    const model = props.model;// || window.models.env.context.active_model;
    const field = window.models.env[model]._fields[props.name];
    const type = field.type;
    if (this.refs.input) {
      await this.setInputValue(value);
    }
    else if (api.hasValue(['many2many', 'one2many', 'many2one', 'one2one'], type) && !props.children) {
      await this.setSelectivityValue(altvalue);
    }
    else if (type === 'selection') {
      if (this.props.widget === 'statusbar') return this.setState({value});
      await this.setSelectivityValue(altvalue);
    }
    else if (api.hasValue(['date', 'datetime'], type)) {
      await this.setState({value, input: this.refs.date_input.base.querySelector('input')});
    }
    else {
      await this.setState({value: altvalue || value});
    }
    return window.models.env.context.refresh();
  }
github rafi16jan / rapyd-framework / client / src / components / pages / CustomPage.jsx View on Github external
function recurse(elements, parent_props) {
    let components = [];
    for (let element of elements) {
      const component = api.hasValue(element.tagName, '-') ? customComponents[element.tagName.split('-').map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase()).join('')] : null || customComponents[element.tagName[0].toUpperCase() + element.tagName.toLowerCase().slice(1)] || customComponents[element.tagName] || element.tagName;
      const props = {model};
      for (let attribute of element.attributes) {
        props[attribute.name] = attribute.value;
      }
      for (let attribute of ['invisible', 'required', 'readonly']) {
        if (api.hasKey(props, attribute)) {
          if (api.hasValue(['true', 'True'], props[attribute])) props[attribute] = true;
          if (api.hasValue(['false', 'False'], props[attribute])) props[attribute] = false;
          if (props[attribute].constructor === Boolean) continue;
          if (api.hasValue(props[attribute], ' == ')) props[attribute] = props[attribute].replace('==', '===');
          if (api.hasValue(props[attribute], ' != ')) props[attribute] = props[attribute].replace('!=', '!==');
          if (api.hasValue(props[attribute], ' === ') || api.hasValue(props[attribute], ' !== ')) props[attribute] = new (Function.prototype.bind.apply(Function, [null, 'active_id', function_string + props[attribute]]))();
        }
      }
      if (props.domain) props.domain = new (Function.prototype.bind.apply(Function, [null, 'active_id', function_string + '[' + props.domain + ']']))();
      if (component === Tree) {
        const field = window.models.env[model]._fields[parent_props.name];
        props.view_model = model;
        props.field_name = parent_props.name;
        props.model = field.relation;
        props.field = field.type === 'one2many' ? field.inverse : parent_props.name;
        if (field.type !== 'one2many') {
          props.parent_model = model;
          props.tree_arch = element.outerHTML;
        }
        if (parent_props.invisible) props.invisible = parent_props.invisible;
        if (parent_props.domain) props.domain = parent_props.domain;
      }
github rafi16jan / rapyd-framework / client / src / components / pages / CustomPage.jsx View on Github external
function recurse(elements, parent_props) {
    let components = [];
    for (let element of elements) {
      const component = api.hasValue(element.tagName, '-') ? customComponents[element.tagName.split('-').map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase()).join('')] : null || customComponents[element.tagName[0].toUpperCase() + element.tagName.toLowerCase().slice(1)] || customComponents[element.tagName] || element.tagName;
      const props = {model};
      for (let attribute of element.attributes) {
        props[attribute.name] = attribute.value;
      }
      for (let attribute of ['invisible', 'required', 'readonly']) {
        if (api.hasKey(props, attribute)) {
          if (api.hasValue(['true', 'True'], props[attribute])) props[attribute] = true;
          if (api.hasValue(['false', 'False'], props[attribute])) props[attribute] = false;
          if (props[attribute].constructor === Boolean) continue;
          if (api.hasValue(props[attribute], ' == ')) props[attribute] = props[attribute].replace('==', '===');
          if (api.hasValue(props[attribute], ' != ')) props[attribute] = props[attribute].replace('!=', '!==');
          if (api.hasValue(props[attribute], ' === ') || api.hasValue(props[attribute], ' !== ')) props[attribute] = new (Function.prototype.bind.apply(Function, [null, 'active_id', function_string + props[attribute]]))();
        }
      }
      if (props.domain) props.domain = new (Function.prototype.bind.apply(Function, [null, 'active_id', function_string + '[' + props.domain + ']']))();
      if (component === Tree) {
github rafi16jan / rapyd-framework / client / src / components / pages / FormPage.jsx View on Github external
function recurse(elements, parent_props) {
    let components = [];
    for (let element of elements) {
      const component = api.hasValue(element.tagName, '-') ? customComponents[element.tagName.split('-').map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase()).join('')] : null || customComponents[element.tagName[0].toUpperCase() + element.tagName.toLowerCase().slice(1)] || customComponents[element.tagName] || element.tagName;
      const props = {model};
      for (let attribute of element.attributes) {
        props[attribute.name] = attribute.value;
      }
      for (let attribute of ['invisible', 'required', 'readonly', 'create', 'choose']) {
        if (api.hasKey(props, attribute)) {
          if (api.hasValue(['true', 'True'], props[attribute])) props[attribute] = true;
          if (api.hasValue(['false', 'False'], props[attribute])) props[attribute] = false;
          if (props[attribute].constructor === Boolean) continue;
          if (api.hasValue(props[attribute], ' == ')) props[attribute] = props[attribute].replace('==', '===');
          if (api.hasValue(props[attribute], ' != ')) props[attribute] = props[attribute].replace('!=', '!==');
          if (api.hasValue(props[attribute], ' === ') || api.hasValue(props[attribute], ' !== ')) props[attribute] = new (Function.prototype.bind.apply(Function, [null, 'active_id', 'parent', function_string + props[attribute]]))();
        }
      }
      if (props.domain) props.domain = new (Function.prototype.bind.apply(Function, [null, 'active_id', 'parent', function_string + '[' + props.domain + ']']))();
      if (component === Tree) {
github rafi16jan / rapyd-framework / client / src / components / pages / FormPage.jsx View on Github external
function recurse(elements, parent_props) {
    let components = [];
    for (let element of elements) {
      const component = api.hasValue(element.tagName, '-') ? customComponents[element.tagName.split('-').map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase()).join('')] : null || customComponents[element.tagName[0].toUpperCase() + element.tagName.toLowerCase().slice(1)] || customComponents[element.tagName] || element.tagName;
      const props = {model};
      for (let attribute of element.attributes) {
        props[attribute.name] = attribute.value;
      }
      for (let attribute of ['invisible', 'required', 'readonly', 'create', 'choose']) {
        if (api.hasKey(props, attribute)) {
          if (api.hasValue(['true', 'True'], props[attribute])) props[attribute] = true;
          if (api.hasValue(['false', 'False'], props[attribute])) props[attribute] = false;
          if (props[attribute].constructor === Boolean) continue;
          if (api.hasValue(props[attribute], ' == ')) props[attribute] = props[attribute].replace('==', '===');
          if (api.hasValue(props[attribute], ' != ')) props[attribute] = props[attribute].replace('!=', '!==');
          if (api.hasValue(props[attribute], ' === ') || api.hasValue(props[attribute], ' !== ')) props[attribute] = new (Function.prototype.bind.apply(Function, [null, 'active_id', 'parent', function_string + props[attribute]]))();
        }
      }
      if (props.domain) props.domain = new (Function.prototype.bind.apply(Function, [null, 'active_id', 'parent', function_string + '[' + props.domain + ']']))();
      if (component === Tree) {
        const field = window.models.env[model]._fields[parent_props.name];
        props.view_model = model;
        props.field_name = parent_props.name;
        props.model = field.relation;
        props.field = field.type === 'one2many' ? field.inverse : parent_props.name;
        if (field.type !== 'one2many') {
          props.parent_model = model;
          props.tree_arch = element.outerHTML;
        }
        if (parent_props.invisible) props.invisible = parent_props.invisible;
        if (parent_props.domain) props.domain = parent_props.domain;
      }
github rafi16jan / rapyd-framework / client / src / components / pages / FormPage.jsx View on Github external
function recurse(elements, parent_props) {
    let components = [];
    for (let element of elements) {
      const component = api.hasValue(element.tagName, '-') ? customComponents[element.tagName.split('-').map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase()).join('')] : null || customComponents[element.tagName[0].toUpperCase() + element.tagName.toLowerCase().slice(1)] || customComponents[element.tagName] || element.tagName;
      const props = {model};
      for (let attribute of element.attributes) {
        props[attribute.name] = attribute.value;
      }
      for (let attribute of ['invisible', 'required', 'readonly', 'create', 'choose']) {
        if (api.hasKey(props, attribute)) {
          if (api.hasValue(['true', 'True'], props[attribute])) props[attribute] = true;
          if (api.hasValue(['false', 'False'], props[attribute])) props[attribute] = false;
          if (props[attribute].constructor === Boolean) continue;
          if (api.hasValue(props[attribute], ' == ')) props[attribute] = props[attribute].replace('==', '===');
          if (api.hasValue(props[attribute], ' != ')) props[attribute] = props[attribute].replace('!=', '!==');
          if (api.hasValue(props[attribute], ' === ') || api.hasValue(props[attribute], ' !== ')) props[attribute] = new (Function.prototype.bind.apply(Function, [null, 'active_id', 'parent', function_string + props[attribute]]))();
        }
      }
      if (props.domain) props.domain = new (Function.prototype.bind.apply(Function, [null, 'active_id', 'parent', function_string + '[' + props.domain + ']']))();
      if (component === Tree) {
        const field = window.models.env[model]._fields[parent_props.name];
        props.view_model = model;
        props.field_name = parent_props.name;
        props.model = field.relation;
        props.field = field.type === 'one2many' ? field.inverse : parent_props.name;
        if (field.type !== 'one2many') {
          props.parent_model = model;
          props.tree_arch = element.outerHTML;
        }
        if (parent_props.invisible) props.invisible = parent_props.invisible;
        if (parent_props.domain) props.domain = parent_props.domain;
github rafi16jan / rapyd-framework / client / src / components / pages / TreePage.jsx View on Github external
function recurse(elements, parent_props) {
    let components = [];
    for (let element of elements) {
      const component = customComponents[element.tagName[0].toUpperCase() + element.tagName.toLowerCase().slice(1)] || customComponents[element.tagName] || element.tagName;
      const props = {model, view_model: model};
      for (let attribute of element.attributes) {
        props[attribute.name] = attribute.value;
      }
      for (let attribute of ['invisible', 'required', 'readonly']) {
        if (api.hasKey(props, attribute)) {
          if (api.hasValue(['true', 'True'], props[attribute])) props[attribute] = true;
          if (api.hasValue(['false', 'False'], props[attribute])) props[attribute] = false;
          if (props[attribute].constructor === Boolean) continue;
          if (api.hasValue(props[attribute], ' == ')) props[attribute] = props[attribute].replace('==', '===');
          if (api.hasValue(props[attribute], ' != ')) props[attribute] = props[attribute].replace('!=', '!==');
          if (api.hasValue(props[attribute], ' === ') || api.hasValue(props[attribute], ' !== ')) props[attribute] = new (Function.prototype.bind.apply(Function, [null, 'active_id', function_string + props[attribute]]))();
        }
      }
      if (props.domain) props.domain = new (Function.prototype.bind.apply(Function, [null, 'active_id', function_string + '[' + props.domain + ']']))();
      props.isTreeView = true;
      const children = recurse(element.children, props) || [(() => element.innerHTML)];
      components.push(() => React.createElement(component, props, children.map((result) => result())));
    }
    if (!components.length) return null;
    return components
  }
  return recurse([view], true)[0];
github rafi16jan / rapyd-framework / client / src / components / pages / TreePage.jsx View on Github external
function recurse(elements, parent_props) {
    let components = [];
    for (let element of elements) {
      const component = customComponents[element.tagName[0].toUpperCase() + element.tagName.toLowerCase().slice(1)] || customComponents[element.tagName] || element.tagName;
      const props = {model, view_model: model};
      for (let attribute of element.attributes) {
        props[attribute.name] = attribute.value;
      }
      for (let attribute of ['invisible', 'required', 'readonly']) {
        if (api.hasKey(props, attribute)) {
          if (api.hasValue(['true', 'True'], props[attribute])) props[attribute] = true;
          if (api.hasValue(['false', 'False'], props[attribute])) props[attribute] = false;
          if (props[attribute].constructor === Boolean) continue;
          if (api.hasValue(props[attribute], ' == ')) props[attribute] = props[attribute].replace('==', '===');
          if (api.hasValue(props[attribute], ' != ')) props[attribute] = props[attribute].replace('!=', '!==');
          if (api.hasValue(props[attribute], ' === ') || api.hasValue(props[attribute], ' !== ')) props[attribute] = new (Function.prototype.bind.apply(Function, [null, 'active_id', function_string + props[attribute]]))();
        }
      }
      if (props.domain) props.domain = new (Function.prototype.bind.apply(Function, [null, 'active_id', function_string + '[' + props.domain + ']']))();
      props.isTreeView = true;
      const children = recurse(element.children, props) || [(() => element.innerHTML)];
      components.push(() => React.createElement(component, props, children.map((result) => result())));
    }
    if (!components.length) return null;
    return components
  }
  return recurse([view], true)[0];