<!-- Wappler include head-page="layouts/smain" fontawesome_5="cdn" bootstrap5="local" is="dmx-app" id="dspec2" appconnect="local" components="{dmxBootstrap5Modal:{},dmxStateManagement:{},dmxFormatter:{},dmxDatastore:{},dmxDatePicker:{},dmxBootstrap5TableGenerator:{},dmxDataTraversal:{},dmxBrowser:{}}" jquery_slim_35="cdn" moment_2="cdn" -->
<div is="dmx-browser" id="browser1"></div>
<meta name="ac:route" content="/dspec2">
<script is="dmx-flow" id="flow1" type="text/dmx-flow" autorun="true">{
  condition: {
    if: "{{query1.data.id}}",
    then: {
      steps: {
        run: {action: "{{var_partid.setValue(query1.data.id)}}", outputType: "text"}
      }
    },
    else: {
      steps: {
        run: {action: "{{api_allparttypes.load({})}}", outputType: "text"}
      }
    },
    outputType: "boolean"
  }
}</script>
<dmx-query-manager id="query1"></dmx-query-manager>
<dmx-serverconnect id="conn_basedata" url="/api/DSpec/basedatasets"></dmx-serverconnect>
<div class="container visually-hidden">
    <div class="row">
        <div class="col">
            <input id="txt_useriddefault" name="useriddefault" type="text" class="form-control" value="-1">
            <input id="txt_testviewlocatioonid" name="viewlocationid" type="text" class="form-control" value="14">
            <input id="txt_testpartid" name="testpartid" type="text" class="form-control" dmx-bind:value="api_postpart.data.id">
        </div>
    </div>
</div>
<dmx-value id="var_comment"></dmx-value>
<dmx-value id="var_copy" dmx-bind:value="false"></dmx-value>
<dmx-value id="var_description"></dmx-value>
<dmx-value id="var_dspecid" dmx-bind:value="0"></dmx-value>
<dmx-value id="var_existingpartid" dmx-bind:value="0" dmx-on:updated=""></dmx-value>
<dmx-value id="var_listmaxdspec" dmx-on:updated="var_dspecid.setValue(value.getValueOrKey('id'))"></dmx-value>
<dmx-value id="var_newdspec" dmx-bind:value="0"></dmx-value>
<dmx-value id="var_partnumber" dmx-bind:value="var_parttypeid.value.toNumber().toString().concat('-'.concat(var_partcodeid.value.concat('-'.concat(api_maxpn.data.number))))"></dmx-value>
<dmx-value id="var_partcodeid" dmx-on:updated="api_getpartcodebyid.load({})"></dmx-value>
<dmx-value id="var_partid" dmx-on:updated="api_getnewpartinfo.load({})"></dmx-value>
<dmx-value id="var_parttypeid"></dmx-value>
<dmx-value id="var_prevdspecid"></dmx-value>
<dmx-value id="var_rev" dmx-bind:value="0"></dmx-value>
<dmx-value id="var_statusid" dmx-bind:value="1"></dmx-value>
<dmx-value id="var_statusiddspec" dmx-bind:value="4"></dmx-value>










<dmx-api-action id="api_allparttypes" dmx-bind:url="pg_apiurl.value.concat('parttypes')" dmx-on:success="mdl_newpart.inp_parttypes.setValue(-1)" noload="true"></dmx-api-action>
<dmx-api-action id="api_bominsertitem" noload="true" method="post" data-type="json" dmx-bind:url="pg_apiurl.value.concat('boms/wapplerinsert')" dmx-data:updatedate="NOW" dmx-data:viewlocationid="txt_testviewlocatioonid.value" dmx-data:old="inp_bomold.value" dmx-data:createdate="NOW" dmx-data:designspecid="var_dspecid.value.toNumber().toString()" dmx-data:createuserid="txt_useriddefault.value" dmx-data:new="inp_bomnew.value" dmx-data:updateuserid="txt_useriddefault.value" dmx-data:partnumberid="btn_bomadditem.value" dmx-on:success="api_loadbombydspec.load({},true)"></dmx-api-action>
<dmx-api-action id="api_bomcopyitem" noload="true" method="put" data-type="json" dmx-bind:url="pg_apiurl.value.concat('boms/copy/'.concat(mod_copybom.inp_cpybomnewdspecid1.value.concat('/'.concat(mod_copybom.inp_cpybomdspecid.value))))" dmx-on:success="api_loadexistingdspec.load({})"></dmx-api-action>



<dmx-api-action id="api_loaddspec" noload="true" dmx-bind:url="pg_apiurl.value.concat('designspecs/'.concat(var_dspecid.value))" dmx-on:success="view_rev.setValue(api_loaddspec.data.revisionlevel);view_partcode.setValue(api_getnewpartinfo.data.partcode.name);view_obsolete.select((api_getnewpartinfo.data.status.id == 2));view_replacedby.setValue(api_getnewpartinfo.data.replacedby.number);view_description.setValue(api_getnewpartinfo.data.description);view_comments.setValue(api_getnewpartinfo.data.comments);inp_reasonforchange.setValue(api_loaddspec.data.reasonforchange);inp_validation.setValue(api_loaddspec.data.validation);inp_notes.setValue(api_loaddspec.data.note);api_loadbombydspec.load({})"></dmx-api-action>
<dmx-api-action id="api_bompartselectbynumber" noload="true" dmx-bind:url="pg_apiurl.value.concat('partnumbers/num/'.concat(inp_bompartnumber.value))" dmx-on:success="inp_bomptdescription.setValue(api_bompartselectbynumber.data.description)"></dmx-api-action>
<dmx-api-action id="api_loadexistingdspec" noload="true" dmx-bind:url="pg_apiurl.value.concat('designspecs/max/'.concat(var_partid.value))" dmx-on:success="run([{run:{action:`var_dspecid.setValue(api_loadexistingdspec.data.id)`,outputType:'text'}},{run:{action:`api_loaddspec.load({})`,outputType:'text'}}])"></dmx-api-action>
<dmx-api-action id="api_filteredpartcodes" noload="true" dmx-bind:url="pg_apiurl.value.concat('partcodes/bytype/'.concat(mdl_newpart.inp_parttypes.value))"></dmx-api-action>
<dmx-api-action id="api_getnewpartinfo" noload="true" dmx-bind:url="pg_apiurl.value.concat('partnumbers/id/'.concat(var_partid.value))" dmx-on:success="run([{run:{action:`view_partnumber.setValue(api_getnewpartinfo.data.number)`,outputType:'text'}},{run:{action:`var_parttypeid.setValue(api_getnewpartinfo.data.partcode.parttype.id);var_partcodeid.setValue(api_getnewpartinfo.data.partcode.id);var_partnumber.setValue(api_getnewpartinfo.data.number);var_description.setValue(api_getnewpartinfo.data.description);var_comment.setValue(api_getnewpartinfo.data.comments)`,outputType:'text'}},{condition:{if:`query1.data.id`,then:{steps:{run:{action:`api_loadexistingdspec.load({})`,outputType:'text'}}},outputType:'boolean'}},{condition:{if:`(api_getnewpartinfo.data.partcode.parttype.id == 2)`,then:{steps:{run:{action:`browser1.goto(\'/dspeckit?id=\'+api_getnewpartinfo.data.id,true,\'New Kit\')`,outputType:'text'}}},else:{steps:{condition:{if:`(api_getnewpartinfo.data.partcode.parttype.id == 3)`,then:{steps:{run:{action:`browser1.goto(\'/dspeckit?id=\'+api_getnewpartinfo.data.id,true,\'New Kit\')`,outputType:'text'}}},else:{steps:{condition:{if:`(api_getnewpartinfo.data.partcode.parttype.id == 4)`,then:{steps:{run:{action:`browser1.goto(\'/dspeckit?id=\'+api_getnewpartinfo.data.id,true,\'Kit\')`,outputType:'text'}}},outputType:'boolean'}}},outputType:'boolean'}}},outputType:'boolean'}}])"></dmx-api-action>
<dmx-api-action id="api_getpartcodebyid" dmx-bind:url="pg_apiurl.value.concat('partcodes/'.concat(var_partcodeid.value))" noload="true" dmx-on:success="view_partcode.setValue(api_getpartcodebyid.data.name)"></dmx-api-action>
<dmx-api-action id="api_getparttypebyid" noload="true" dmx-bind:url="pg_apiurl.value.concat('parttypes/'.concat(var_parttypeid.value))"></dmx-api-action>
<dmx-api-action id="api_getexistingpartinfo" noload="true" dmx-bind:url="pg_apiurl.value.concat('partnumbers/id/'.concat(var_existingpartid.value))" dmx-on:success="var_partid.setValue(api_getnewpartinfo.data.id);view_partnumber.setValue(api_getnewpartinfo.data.number)"></dmx-api-action>
<dmx-api-action id="api_increasepn" noload="true" method="post" dmx-data:number="(api_maxpn.data.number + 1)" dmx-bind:url="pg_apiurl.value.concat('pns')" dmx-on:success="api_getnewpartinfo.load({})"></dmx-api-action>
<dmx-api-action id="api_maxpn" dmx-on:success="run([{run:{action:`var_partnumber.setValue(var_parttypeid.value.toNumber().toString().concat(\'-\'.concat(var_partcodeid.value.concat(\'-\'.concat(api_maxpn.data.number)))))`,outputType:'text'}},{run:{action:`api_postpart.load({})`,outputType:'text'}}])" noload="true" dmx-bind:url="pg_apiurl.value.concat('pns/max')"></dmx-api-action>


<dmx-api-action id="api_postdspec" noload="true" method="post" dmx-data:revisionlevel="view_rev.value" dmx-data:partnumberid="var_partid.value.toNumber()" dmx-data:statusidpn="var_statusid.value.toNumber().toString()" dmx-data:partcodeid="var_partcodeid.value.toNumber().toString()" dmx-data:parttypeid="var_partid.value.toNumber().toString()" dmx-data:statusiddspec="var_statusiddspec.value.toNumber().toString()" dmx-data:effectivedate="inp_effectivedate.value" dmx-data:reasonforchange="inp_reasonforchange.value" dmx-data:validation="inp_validation.value" dmx-data:notes="inp_notes.value" dmx-bind:url="pg_apiurl.value.concat('designspecs/alt')" dmx-on:success="var_dspecid.setValue(api_postdspec.data.id)"></dmx-api-action>
<dmx-api-action id="api_copydspec" noload="true" method="post" dmx-data:revisionlevel="var_rev.value" dmx-data:partnumberid="var_partid.value.toNumber()" dmx-data:statusidpn="var_statusid.value.toNumber().toString()" dmx-data:partcodeid="var_partcodeid.value.toNumber().toString()" dmx-data:parttypeid="var_partid.value.toNumber().toString()" dmx-data:statusiddspec="var_statusiddspec.value.toNumber().toString()" dmx-data:effectivedate="inp_effectivedate.value" dmx-data:reasonforchange="inp_reasonforchange.value" dmx-data:validation="inp_validation.value" dmx-data:notes="inp_notes.value" dmx-bind:url="pg_apiurl.value.concat('designspecs/alt')" dmx-on:success="run({meta:{$param:[{type:'number',name:'count'},{type:'number',name:'index'}]},exec:{steps:[{run:{action:`var_dspecid.setValue(api_copydspec.data.id)`,outputType:'text'}},{run:{action:`view_rev.setValue(api_copydspec.data.revisionlevel)`,outputType:'text'}},{run:{action:`mod_copybom.show()`,outputType:'text'}}]}})"></dmx-api-action>
















<dmx-api-action id="api_postpart" noload="true" method="post" data-type="json" dmx-data:number="var_partnumber.value" dmx-data:statusid="var_statusid.value" dmx-data:description="var_description.value" dmx-data:comments="var_comment.value" dmx-data:partcodeid="var_partcodeid.value.toNumber().toString()" dmx-data:parttypeid="var_parttypeid.value.toNumber().toString()" dmx-bind:url="pg_apiurl.value.concat('partnumbers/alt')" dmx-on:success="run([{run:{action:`var_partid.setValue(api_postpart.data.id)`,outputType:'text'}},{run:{action:`mdl_newpart.hide()`,outputType:'text'}},{run:{action:`api_increasepn.load({})`,outputType:'text'}}])"></dmx-api-action>
<div class="modal" id="mod_copybom" is="dmx-bs5-modal" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Copy Bom?</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body visually-hidden">
                <input id="inp_cpybomdspecid" name="cpybomdspecid" type="text" class="form-control" dmx-bind:value="api_loaddspec.data.id">
                <input id="inp_cpybomnewdspecid1" name="cpybomnewdspecid1" type="text" class="form-control" dmx-bind:value="api_copydspec.data.id">
                <p>Modal body text goes here.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-bs-dismiss="modal" dmx-on:click="api_bomcopyitem.load({})">Yes</button>
                <button type="button" class="btn btn-danger" dmx-on:click="api_loadexistingdspec.load({})">No</button>
            </div>
        </div>
    </div>
</div>










<div class="modal" id="mdl_newpart" is="dmx-bs5-modal" tabindex="-1" dmx-bind:show="!query1.data.id">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">New Part</h5>
            </div>
            <div class="modal-body">
                <div class="container">
                    <div class="row">
                        <div class="col">
                            <div class="form-group mb-3 row">
                                <label for="hdnpartnumber" class="col-sm-2 col-form-label gy-0 gx-0 visually-hidden" style="width: 20%;">Part Number</label>
                                <div class="col-sm-10" style="width: 75%;">
                                    <input id="hdn_partnumber" name="hdnpartnumber" type="text" class="form-control visually-hidden">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <div class="form-group mb-3 row">
                                <label for="parttypes" class="col-sm-2 col-form-label gy-0 gx-0" style="width: 20%;">Part Types</label>
                                <div class="col-sm-10" style="width: 55%; float: left;">
                                    <select id="inp_parttypes" class="form-select" name="parttypes" dmx-bind:options="conn_basedata.data.parttypes.data" optiontext="name" optionvalue="id" dmx-on:changed="api_filteredpartcodes.load({})">
                                        <option value="-1">Select</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <div class="form-group mb-3 row">
                                <label for="partcodes" class="col-sm-2 col-form-label gy-0 gx-0" style="width: 20%;">Part Codes</label>
                                <div class="col-sm-10" style="width: 55%; float: left;">
                                    <select id="inp_partcodes" class="form-select" name="partcodes" dmx-bind:options="conn_basedata.data.partcodes.data.where(`parttype.id`, inp_parttypes.value, '==')" optiontext="name" optionvalue="id" dmx-on:changed="var_partcodeid.setValue(value)">
                                        <option value="0">Select</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <label claclass="col-sm-2 col-form-label gy-0 gx-0">Description</label>
                            <textarea id="inp_description" class="form-control" name="description"></textarea>
                        </div>

                    </div>
                    <div class="row">
                        <div class="col">
                            <label claclass="col-sm-2 col-form-label gy-0 gx-0">Comments</label>
                            <textarea id="inp_comments" class="form-control" name="comments"></textarea>
                        </div>
                    </div>
                </div>

                <input id="inp_partid" name="partid" type="text" class="form-control visually-hidden" dmx-bind:value="api_postpart.data.id">
                <input id="text1" name="text1" type="password" class="form-control">




            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" dmx-on:click="run([{run:{action:`var_description.setValue(inp_description.value)`,outputType:'text'}},{run:{action:`var_comment.setValue(inp_comments.value)`,outputType:'text'}},{run:{action:`var_parttypeid.setValue(api_getpartcodebyid.data.parttype.id)`,outputType:'text'}},{wait:{delay:1000}},{run:{action:`api_maxpn.load({})`,outputType:'text'}}])">Save</button>
            </div>
        </div>
    </div>
</div>
<div class="container">
    <div class="row">
        <div class="col placeholder-glow border-3 rounded rounded-3 border-dark">
            <div class="card border-1 border-dark rounded rounded-3">
                <div class="card-body">

                    <div class="btn-group" role="group" aria-label="Button Group">
                        <button id="btn_revup" class="btn btn-danger" dmx-on:click="run([{run:{action:`var_rev.setValue(view_rev.value)`,outputType:'text'}},{run:{action:`var_prevdspecid.setValue(var_dspecid.value)`,outputType:'text'}},{run:{action:`api_copydspec.load({})`,outputType:'text'}}])">New Rev</button>
                    </div>
                    <h4 class="card-title" id="crd_partinfo">
                        <div style="float: left; padding-right: 10px;">Part Info: </div>

                        <input type="text" class="form-control" id="view_partnumber" name="viewpartnumber" aria-describedby="input1_help" readonly="true" style="width: 30%; float: left; padding-right: 10px;">

                        <div style="float: left; padding-right: 10px; padding-left: 10px;">Rev:</div>

                        <input type="text" class="form-control" id="view_rev" name="viewrev" aria-describedby="input1_help" readonly="true" style="width: 10%; float: left;" value="0" dmx-bind:value="var_rev.value">
                    </h4>
                    <div class="row" style="padding-top: 10px;">
                        <div class="col" style="width: 33%;">
                            <div class="form-group mb-3 row">
                                <label for="view_partcode" class="col-sm-2 col-form-label" style="width: 30%;">Part Code:</label>
                                <div class="col-sm-10" style="width: 50%">
                                    <input type="text" class="form-control" id="view_partcode" name="viewpartcode" aria-describedby="input1_help" readonly="true" dmx-bind:value="api_getpartinfo.data.partcode.name">
                                </div>
                            </div>

                        </div>
                        <div class="col" style="width:33%;">
                            <div class="form-group mb-3 row">
                                <div class="col-sm-10">
                                    <div class="form-check">
                                        <input class="form-check-input" type="checkbox" value="" id="view_obsolete" name="viewobsolete" readonly="true" disabled="true" dmx-bind:checked="(api_getpartinfo.data.status.id == 2)">
                                        <label class="form-check-label" for="view_obsolete">Obsolete</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col">
                            <div class="form-group mb-3 row">
                                <label for="view_replacedby" style="width: 40%; " class="col-sm-2 col-form-label">Replaced By:</label>
                                <div class="col-sm-10" style="width: 40%; float: left;">
                                    <input type="text" class="form-control" id="view_replacedby" name="viewreplacedby" aria-describedby="input1_help" readonly="true" dmx-bind:value="api_getpartinfo.data.replacedby.number">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <p>Description</p>
                            <textarea id="view_description" class="form-control" name="viewpartdescription" dmx-bind:value="var_description.value" readonly="true"></textarea>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <p>Comments</p>
                            <textarea id="view_comments" class="form-control" name="viewpartcomments" dmx-bind:value="var_comment.value" readonly="true"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col" style="padding-top: 10px;">
            <div class="card border-1 rounded rounded-3 border-dark">
                <div class="card-body">
                    <h4 class="card-title">DSpec</h4>
                    <div class="row">
                        <div class="col" style="width= 30%; float: left;">
                            <div class="form-group mb-3 row">
                                <div style="float: left;">
                                    <label for="inp_effectivedate" class="col-sm-2 col-form-label" style="width: 35%; float: left;">Effective Date</label>
                                    <div class="col-sm-10">
                                        <input id="inp_effectivedate" name="effectivedate" type="date" class="form-control">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col">
                            <div class="form-group mb-3 row">
                                <div style="float: left;">
                                    <label for="inp_application" class="col-sm-2 col-form-label" style="width: 40%; float: left;">Work Instruction</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" id="inp_workinstruction" name="workinstruction" aria-describedby="input1_help" style="width: 40%; float left;">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col">
                            <div class="form-group mb-3 row">
                                <div style="float: left;">
                                    <label for="inp_application" class="col-sm-2 col-form-label" style="width: 30%; float: left;">Application</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" id="inp_application" name="application" aria-describedby="input1_help" style="width: 60%; float left;">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <label for="inp_reasonforchange" class="col-sm-2 col-form-label">Reason for Change</label>
                            <textarea id="inp_reasonforchange" class="form-control" name="reasonforchange"></textarea>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <label for="inp_validation" class="col-sm-2 col-form-label">Validation</label>
                            <textarea id="inp_validation" class="form-control" name="validation"></textarea>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <label for="inp_notes" class="col-sm-2 col-form-label">Notes</label>
                            <textarea id="inp_notes" class="form-control" name="notes"></textarea>
                        </div>
                    </div>
                    <div class="row" style="padding-top: 10px;">
                        <div class="col">
                            <button id="btn_savedspec" class="btn btn-success" style="float: right; padding-top: 5px;" dmx-on:click="api_postdspec.load({})">Save</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col rounded rounded-3 border-dark border-5">
            <dmx-api-action id="api_loadbombydspec" noload="true" dmx-bind:url="pg_apiurl.value.concat('boms/bydspec/'.concat(var_dspecid.value))" dmx-on:success=""></dmx-api-action>
            <dmx-api-action id="api_deletethisitem" noload="true" method="delete" dmx-bind:url="pg_apiurl.value.concat('boms/'.concat(var_partidtodelete.value))"></dmx-api-action>
            <dmx-value id="var_partidtodelete"></dmx-value>
            <p>BOM</p>
            <div class="table-responsive" id="tbl_bom">
                <table class="table">
                    <thead>
                        <tr>
                            <th scope="col">Part Number</th>
                            <th scope="col">Description</th>
                            <th scope="col">Old</th>
                            <th scope="col">New</th>
                            <th scope="row">Actions</th>
                        </tr>
                        <tr>
                            <td>
                                <input id="inp_bompartnumber" name="bompartnumber" type="text" class="form-control" dmx-on:blur="api_bompartselectbynumber.load({})">
                            </td>
                            <td>{{api_bompartselectbynumber.data.description}}</td>
                            <td>
                                <input id="inp_bomold" name="bomold" type="text" class="form-control">
                            </td>
                            <td>
                                <input id="inp_bomnew" name="bomnew" type="text" class="form-control">
                            </td>
                            <td>
                                <button id="btn_bomadditem" class="btn btn-success" dmx-on:click="api_bominsertitem.load({})" dmx-bind:value="api_bompartselectbynumber.data.id">Add</button>
                            </td>
                        </tr>
                    </thead>
                    <tbody id="tb_bom" is="dmx-repeat" dmx-bind:repeat="api_loadbombydspec.data" key="id">
                        <tr>
                            <td>{{partnumber}}</td>
                            <td>{{description}}</td>
                            <td>{{old}}</td>
                            <td>{{new}}</td>
                            <td><button id="btn_bomdeleteitem" class="btn btn-danger" dmx-on:click="var_partidtodelete.setValue(value)" dmx-bind:value="id">X</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>