<commit_before>class LevelUp {
  fetch(entity, attributes, filter) {
      let headers = new Headers({
        "Accept" : "application/json",
        "Content-Type" : "application/json; charset=utf-8",
      });
      let serviceUrl = `${this.clientUrl}/XRMServices/2011/OrganizationData.svc/${entity}`;
      if(this.is2016) {
          headers = new Headers({
            "Accept" : "application/json",
            "Content-Type" : "application/json; charset=utf-8",
            "OData-MaxVersion" : "4.0",
            "OData-Version" : "4.0"
          });
          serviceUrl = `/api/data/v8.0/${entity}`;
      }
      if(attributes){
        serviceUrl += `?$select=${attributes}`;
      }      
      if(filter) {
        serviceUrl += `&$filter=${filter}`;
      }
      return fetch(serviceUrl, {
        method : 'GET',
        headers : headers,
        credentials : 'include'
      }).then((response) => {
        return response.json();
      }).then((c) => {
        if(c.d){
          return c.d.results;
        }
        else if (c.value) {
          return c.value;
        }
      }).catch ((err) => {
        console.log(err);
      });    
  }

  messageExtension(message, category) {
       let levelUpEvent = new CustomEvent('levelup', { 'detail': { type: 'page', category: category, content: message} });
       levelUpEvent.initEvent('levelup', false, false);
       document.dispatchEvent(levelUpEvent);
  }
    
  openRecord(entityName, entityId) {
    if(!entityName) {
      entityName = prompt("Entity?", "");
    }
    if(entityName && !entityId) {
      entityId = prompt("Id?", "");
    }
    if(entityId) {
      window.open(`${this.clientUrl}/main.aspx?etn=${entityName}&id=${entityId}&newWindow=true&pagetype=entityrecord`, '_blank');
    }
  }
  
  displayLogicalNames() {
      let setLabels = (Xrm) => {
        Xrm.Page.data.entity.attributes.forEach(a => {
          a.controls.forEach(function (c) {
            var lblText = c.getLabel();
            c.setVisible(true);
            var attr = a.getName();
            var lbl = $('#' + c.getName() + '_c').html('');
            lbl.css('text-align', 'left');
            if (lbl.is('td')) {
              lbl.closest('table').children('colgroup').children('col:even').attr('width', '400');
            }
            $('<input/>').width(200).val(attr).appendTo(lbl).focus(function () {
              $(this).select();
            });
            $('<span></span>').text(lblText).appendTo(lbl);
          });
        });
      };
      
      let waitForJQ = () => {
        if (this.formWindow.jQuery) {
          $ = this.formWindow.jQuery.noConflict(true);
          setLabels(this.Xrm);
        } else {
          setTimeout(waitForJQ, 1000);
        }
      }
            
      this.Xrm.Page.ui.tabs.forEach(function (tab) {
        tab.setVisible(true);
        tab.sections.forEach(function (section) {
          section.setVisible(true);
        });
      });
      
      var $ = this.formWindow.jQuery || (this.formWindow.CEI && this.formWindow.CEI.$);
      if (!$) {
        var head = this.formWindow.document.getElementsByTagName('head').item(0);
        var s = this.formWindow.document.createElement('script');
        s.setAttribute('type', 'text/javascript');
        s.setAttribute('src', 'https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js');
        s.async = false;
        head.appendChild(s);
        waitForJQ();
      } else {
        setLabels(this.Xrm);
      }

      this.Xrm.Page.ui.tabs.forEach(t=>{
        var tabInput = parent.document.createElement('input');
        tabInput.setAttribute('style', 'width:200px');
        tabInput.value = t.getName(); 
        if(tabInput.value){
          this.formWindow.document.getElementsByName(tabInput.value)[0].prepend(tabInput);
        }
        t.sections.forEach(s=>{
          var sectionInput = parent.document.createElement('input'); 
          sectionInput.setAttribute('style', 'width:200px');
          sectionInput.value = s.getName(); 
          if(sectionInput.value){
            this.formWindow.document.getElementsByName(sectionInput.value)[0].prepend(sectionInput);
          }
        });
      });      
  }
  
  godMode() {
      this.Xrm.Page.data.entity.attributes.forEach(a => a.setRequiredLevel('none'));
      
      this.Xrm.Page.ui.controls.forEach(c => {
          c.setVisible(true);
          if(c.setDisabled){
            c.setDisabled(false);
          }
          c.clearNotification();
      });
      
      this.Xrm.Page.ui.tabs.forEach(t => {
        t.setVisible(true);
        t.setDisplayState('expanded');
        t.sections.forEach(s => s.setVisible(true));
      });
  }
  
  formProperties() {
    var id = this.Xrm.Page.data.entity.getId();
    var etc = this.Xrm.Page.context.getQueryStringParameters().etc;
    window.Mscrm.RibbonActions.openFormProperties(id, etc);
  }
  
  copyRecordUrl() {
      var entityId = this.Xrm.Page.data.entity.getId();
      if (entityId) {
        var locationUrl = `${this.clientUrl}/main.aspx?etn=${this.Xrm.Page.data.entity.getEntityName()}&id=${entityId}&newWindow=true&pagetype=entityrecord`;
        prompt('Ctrl+C to copy. OK to close.', locationUrl);
      }
      else {
        alert('This record has not been saved. Please save and run this command again');
      }
  }
  
  copyRecordId() {
      var entityId = this.Xrm.Page.data.entity.getId();
      if (entityId) {
        prompt('Ctrl+C to copy. OK to close.', this.Xrm.Page.data.entity.getId());
      }
      else{
        alert('This record has not been saved. Please save and run this command again');
      }
  }
  
  openSecurity() {
    window.top.document.getElementById('navBar').control.raiseNavigateRequest({uri: '/tools/AdminSecurity/adminsecurity_area.aspx?pagemode=iframe&'});
  }
  
  openSystemJobs() {
    window.top.document.getElementById('navBar').control.raiseNavigateRequest({uri: '/tools/business/home_asyncoperation.aspx?pagemode=iframe&'});
  }
  
  openSolutions() {
    window.open(`${this.clientUrl}/main.aspx?Origin=Portal&page=Settings&area=nav_solution`);
  }
  
  openProcesses() {
    window.top.document.getElementById('navBar').control.raiseNavigateRequest({uri: '/_root/homepage.aspx?etc=4703&pagemode=iframe&sitemappath=Settings|ProcessCenter|nav_workflow'});
  }
  
  highlightDirtyFields() {
      this.Xrm.Page.ui.controls.forEach(c => {
        if (c.getAttribute) {
          var dirtyAttribute = c.getAttribute();
          if(!dirtyAttribute || !dirtyAttribute.getIsDirty()) return;
          this.formWindow.document.getElementById(dirtyAttribute.getName()).setAttribute('style', 'border: 1px solid red');
        }
      });<commit_msg>copy to clipboard<commit_after>class LevelUp {

  copy(valueToCopy){
    var t = document.createElement('input');
    t.setAttribute('id', 'copy');
    t.setAttribute('value', valueToCopy);
    document.body.appendChild(t);
    t.select();
    document.execCommand('copy');
    t.remove();
  }

  fetch(entity, attributes, filter) {
      let headers = new Headers({
        "Accept" : "application/json",
        "Content-Type" : "application/json; charset=utf-8",
      });
      let serviceUrl = `${this.clientUrl}/XRMServices/2011/OrganizationData.svc/${entity}`;
      if(this.is2016) {
          headers = new Headers({
            "Accept" : "application/json",
            "Content-Type" : "application/json; charset=utf-8",
            "OData-MaxVersion" : "4.0",
            "OData-Version" : "4.0"
          });
          serviceUrl = `/api/data/v8.0/${entity}`;
      }
      if(attributes){
        serviceUrl += `?$select=${attributes}`;
      }      
      if(filter) {
        serviceUrl += `&$filter=${filter}`;
      }
      return fetch(serviceUrl, {
        method : 'GET',
        headers : headers,
        credentials : 'include'
      }).then((response) => {
        return response.json();
      }).then((c) => {
        if(c.d){
          return c.d.results;
        }
        else if (c.value) {
          return c.value;
        }
      }).catch ((err) => {
        console.log(err);
      });    
  }

  messageExtension(message, category) {
       let levelUpEvent = new CustomEvent('levelup', { 'detail': { type: 'page', category: category, content: message} });
       levelUpEvent.initEvent('levelup', false, false);
       document.dispatchEvent(levelUpEvent);
  }
    
  openRecord(entityName, entityId) {
    if(!entityName) {
      entityName = prompt("Entity?", "");
    }
    if(entityName && !entityId) {
      entityId = prompt("Id?", "");
    }
    if(entityId) {
      window.open(`${this.clientUrl}/main.aspx?etn=${entityName}&id=${entityId}&newWindow=true&pagetype=entityrecord`, '_blank');
    }
  }
  
  displayLogicalNames() {
      let setLabels = (Xrm) => {
        Xrm.Page.data.entity.attributes.forEach(a => {
          a.controls.forEach(function (c) {
            var lblText = c.getLabel();
            c.setVisible(true);
            var attr = a.getName();
            var lbl = $('#' + c.getName() + '_c').html('');
            lbl.css('text-align', 'left');
            if (lbl.is('td')) {
              lbl.closest('table').children('colgroup').children('col:even').attr('width', '400');
            }
            $('<input/>').width(200).val(attr).appendTo(lbl).focus(function () {
              $(this).select();
            });
            $('<span></span>').text(lblText).appendTo(lbl);
          });
        });
      };
      
      let waitForJQ = () => {
        if (this.formWindow.jQuery) {
          $ = this.formWindow.jQuery.noConflict(true);
          setLabels(this.Xrm);
        } else {
          setTimeout(waitForJQ, 1000);
        }
      }
            
      this.Xrm.Page.ui.tabs.forEach(function (tab) {
        tab.setVisible(true);
        tab.sections.forEach(function (section) {
          section.setVisible(true);
        });
      });
      
      var $ = this.formWindow.jQuery || (this.formWindow.CEI && this.formWindow.CEI.$);
      if (!$) {
        var head = this.formWindow.document.getElementsByTagName('head').item(0);
        var s = this.formWindow.document.createElement('script');
        s.setAttribute('type', 'text/javascript');
        s.setAttribute('src', 'https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js');
        s.async = false;
        head.appendChild(s);
        waitForJQ();
      } else {
        setLabels(this.Xrm);
      }

      this.Xrm.Page.ui.tabs.forEach(t=>{
        var tabInput = parent.document.createElement('input');
        tabInput.setAttribute('style', 'width:200px');
        tabInput.value = t.getName(); 
        if(tabInput.value){
          this.formWindow.document.getElementsByName(tabInput.value)[0].prepend(tabInput);
        }
        t.sections.forEach(s=>{
          var sectionInput = parent.document.createElement('input'); 
          sectionInput.setAttribute('style', 'width:200px');
          sectionInput.value = s.getName(); 
          if(sectionInput.value){
            this.formWindow.document.getElementsByName(sectionInput.value)[0].prepend(sectionInput);
          }
        });
      });      
  }
  
  godMode() {
      this.Xrm.Page.data.entity.attributes.forEach(a => a.setRequiredLevel('none'));
      
      this.Xrm.Page.ui.controls.forEach(c => {
          c.setVisible(true);
          if(c.setDisabled){
            c.setDisabled(false);
          }
          c.clearNotification();
      });
      
      this.Xrm.Page.ui.tabs.forEach(t => {
        t.setVisible(true);
        t.setDisplayState('expanded');
        t.sections.forEach(s => s.setVisible(true));
      });
  }
  
  formProperties() {
    var id = this.Xrm.Page.data.entity.getId();
    var etc = this.Xrm.Page.context.getQueryStringParameters().etc;
    window.Mscrm.RibbonActions.openFormProperties(id, etc);
  }
  
  copyRecordUrl() {
      let entityId = this.Xrm.Page.data.entity.getId();
      if (entityId) {
        let locationUrl = `${this.clientUrl}/main.aspx?etn=${this.Xrm.Page.data.entity.getEntityName()}&id=${entityId}&newWindow=true&pagetype=entityrecord`;
        try{
          this.copy(locationUrl);
          alert('Record URL has been copied to clipboard');
        }
        catch(e){
          prompt('Ctrl+C to copy. OK to close.', locationUrl);
        }
      }
      else {
        alert('This record has not been saved. Please save and run this command again');
      }
  }
  
  copyRecordId() {
      let entityId = this.Xrm.Page.data.entity.getId();
      if (entityId) {
        try{
          this.copy(entityId);
          alert('Record Id has been copied to clipboard');
        }
        catch(e){
          prompt('Ctrl+C to copy. OK to close.', entityId);
        }        
      }
      else{
        alert('This record has not been saved. Please save and run this command again');
      }
  }
  
  openSecurity() {
    window.top.document.getElementById('navBar').control.raiseNavigateRequest({uri: '/tools/AdminSecurity/adminsecurity_area.aspx?pagemode=iframe&'});
  }
  
  openSystemJobs() {
    window.top.document.getElementById('navBar').control.raiseNavigateRequest({uri: '/tools/business/home_asyncoperation.aspx?pagemode=iframe&'});
  }
  
  openSolutions() {
    window.open(`${this.clientUrl}/main.aspx?Origin=Portal&page=Settings&area=nav_solution`);
  }
  
  openProcesses() {
    window.top.document.getElementById('navBar').control.raiseNavigateRequest({uri: '/_root/homepage.aspx?etc=4703&pagemode=iframe&sitemappath=Settings|ProcessCenter|nav_workflow'});
  }
  
  highlightDirtyFields() {
      this.Xrm.Page.ui.controls.forEach(c => {
        if (c.getAttribute) {
          var dirtyAttribute = c.getAttribute();
          if(!dirtyAttribute || !dirtyAttribute.getIsDirty()) return;
          this.formWindow.document.getElementById(dirtyAttribute.getName()).setAttribute('style', 'border: 1px solid red');
        }
      });
{'fraction_non_alphanumeric': 0.1631144599928238, 'fraction_numerical': 0.00617151058485827, 'mean_word_length': 2.3023696682464454, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2677186', 'n_tokens_mistral': 4323, 'n_tokens_neox': 4293, 'n_words': 590}