| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706 |
- //------------------------Utility------------------------
- function findPosX(obj) { //辅助函数 得到元素左边与浏览器左边的边距
- var curleft = 0;
- if (obj && obj.offsetParent) {
- while (obj.offsetParent) {
- curleft += obj.offsetLeft;
- obj = obj.offsetParent;
- }
- } else if (obj && obj.x)
- curleft += obj.x;
- return curleft; // + document.body.scrollLeft - document.body.clientLeft;
- }
- function findPosY(obj) { //辅助函数 得到元素上边与浏览器上边的边距
- var curtop = 0;
- if (obj && obj.offsetParent) {
- while (obj.offsetParent) {
- curtop += obj.offsetTop;
- obj = obj.offsetParent;
- }
- } else if (obj && obj.y)
- curtop += obj.y;
- return curtop; // + document.body.scrollTop - document.body.clientTop;
- }
- var dragGhost = document.createElement("div");
- dragGhost.style.border = "dashed 1px #CCCCCC";
- dragGhost.style.background = "white";
- dragGhost.style.display = "none";
- dragGhost.style.margin = "10px";
- dragGhost.style.width = "100%";
- var container;
- var keys;
- var columns = [];
- var groups = [];
- //------------------------Start Here------------------------
- $(document).ready(function () {
- // init();
- DM.getDrager().itemClick=function(){
- console.log(this);
- console.log(this.children())
- if(!this.parentid){
- // DM.getDrager().optionList.reload()
- // DM.getDrager().selectedList.reload()
- var thisItem=this;
- if(thisItem.id.indexOf("-") == -1){
- DM.getDrager().optionList.empty();
- var allcodebook=$(thisItem.element).find(".allcodebook");
- var selectedList=DM.getDrager().selectedList.getAllItems()
- selectedId={};
- for(var i=0;i<selectedList.length;i++){
- selectedId[selectedList[i].id]=true;
- }
- var optionList=allcodebook.filter(function(){
- var identify=$(this).find(".receiveCodebook").attr("identify");
- if(selectedId[identify])return false;
- return true;
- }).clone().each(function(){
- var identify=$(this).find(".receiveCodebook").attr("identify");
- $(this).removeClass("allcodebook").attr("ssObjId",identify); // ("wdObjectId",。Lin
- DM.getDrager().optionList.append(this);
- })
- optionList.show();
- DM.getDrager().optionList.reload();
- }
- }
- }
- })
- function initDrag() {
- // console.info("come init()");
- groups = [];
- columns = [];
- container = document.getElementById("containers");
- for (var i = 0; i < container.childNodes.length; i++) {
- if ($(container.childNodes[i]).hasClass("column")) { //筛选出所有的列 ff下的childNodes不可靠 :\
- columns.push(container.childNodes[i]);
- }
- }
- for (var i = 0; i < columns.length; i++) {
- var column = columns[i];
- for (var j = 0; j < column.childNodes.length; j++) {
- var group = column.childNodes[j];
- if (typeof group.className != "undefined") {
- if ($(group).hasClass("group")) {
- group.column = column;
- group.items = group.getElementsByClassName("items")[0];
- groups.push(group);
- }
- }
- }
- }
- // console.log(groups.length)
- for (var i = 0; i < groups.length; i++) {
- var group = groups[i];
- var items = group.querySelectorAll(".item");
- for (var j = 0; j < items.length; j++) {
- items[j].group = group;
- new dragItem(items[j]);
- }
- }
- }
- function init() {
- setTimeout(function () {
- var groups = document.querySelectorAll("#keys .group")
- console.log(groups)
- //修复属性名称被修改是,导致显示正确
- for (var i = 0; i < groups.length; i++) {
- var group = groups[i];
- var codebooks = group.querySelectorAll(".codebook");
- var items = group.querySelectorAll(".item");
- for (var j = 0; j < items.length; j++) {
- var item = items[j];
- for (var k = 0; k < codebooks.length; k++) {
- var codebook = codebooks[k]
- if (item.getAttribute("value") == codebook.getAttribute("value")) {
- // console.log(item)
- // console.log(codebook)
- if (item.getAttribute("html") != codebook.getAttribute("html")) {
- if (window.confirm("类别\"" + codebook.getAttribute("desc") + "\""
- + ",所选\""
- +item.getAttribute("html") + "\"最新为\""
- +codebook.getAttribute("html") + "\""
- + "\n 是否要更新?")) {
- item.setAttribute("html", codebook.getAttribute("html"))
- item.innerHTML = codebook.getAttribute("html")
- }
- }
- }
- }
- }
- // console.log(codebooks)
- }
- }, 3000)
- // console.info("init >>>>>>>");
- //绑定事件,选中并且拖选初始化
- var keys = document.getElementById("keys");
- keys.onclick = function (e) {
- // console.log("click")
- if (!e) {
- e = window.event
- }
- var target = e.target;
- var currentTarget = e.currentTarget;
- var groupNode = null
- for (var i = 0; i < currentTarget.childNodes.length; i++) {
- if (typeof currentTarget.childNodes[i].className == "undefined") {
- continue;
- }
- //定位位置
- if ($(currentTarget.childNodes[i]).hasClass("group")) {
- var aa = currentTarget.childNodes[i].compareDocumentPosition(target);
- if (aa == 0 || aa == 20) {
- groupNode = currentTarget.childNodes[i];
- }
- }
- }
- //找不到 ,返回
- if (groupNode == null) {
- return;
- }
- //点击显示控制
- //移除选中状态
- $(currentTarget).children(".selected").removeClass("selected")
- $("#candidate .item").remove();
- if (lastNode == groupNode) {
- //重复点击关闭
- //移除选中状态
- $(groupNode).removeClass("selected");
- //删除待选
- $(".useobject").remove();
- $(currentTarget).children(".selected").removeClass("selected")
- lastNode = null;
- } else {
- //选中标记
- $(groupNode).addClass("selected");
- $(".useobject").remove();
- // console.log(groupNode)
- $(groupNode).find(".item").each(function (index, element) {
- settingItemMessage(element);
- // console.log(element)
- })
- // 右侧栏显示拖动选项
- $(groupNode).children(".codebook").each(function (index, element) {
- var temp = element.cloneNode(true)
- temp.className = "item list-normal list-background";
- // console.log(codebookname+" "+codebookvalue);
- //排重
- var exit = false;
- $(groupNode).children(".items").children(".item").each(function (ind, ele) {
- if ($(ele).attr("value") == $(temp).attr("value")) {
- exit = true;
- }
- })
- if (exit) {
- return;
- }
- settingItemMessage(temp);
- // $(temp).append("<span style=\"color:red;\">(部门内)</span>");
- $("#candidate .items").append(temp).hide();
- })
- $("#candidate .items").fadeIn(500)
- //重复点击判断
- lastNode = groupNode;
- //拖动初始化
- initDrag()
- }
- }
- }
- //重复点击
- var lastNode;
- var isIE = document.all;
- //------------------------Drag Item------------------------
- function dragItem(item) {
- var handle = item;
- if (!handle)
- return;
- Drag.init(handle, item);
- item.onDragStart = function (left, top, mouseX, mouseY) {
- this.lock = this.lockDrag();
- if (this.lock) {
- return
- };
- //将ghost插入到当前位置
- dragGhost.style.display = "block";
- //开始拖动的时候设置透明度
- this.style.opacity = "0.5";
- this.style.filter = "alpha(opacity=50)";
- dragGhost.style.height = (isIE ? this.offsetHeight : this.offsetHeight - 2) + "px";
- //this指的是item
- this.style.width = this.offsetWidth + "px"; //因为初始的width为auto
- var scrollTop = this.parentNode.scrollTop;
- this.style.left = (findPosX(this) - 5) + "px";
- this.style.top = (findPosY(this) - scrollTop) + "px";
- this.style.position = "absolute";
- // console.log(this.group)
- // this.group.insertBefore(dragGhost,this);
- // console.log(this.group.items)
- this.group.items.insertBefore(dragGhost, this);
- //记录每一列的左边距 在拖动过程中判断拖动对象所在的列会用到
- this.columnsX = [];
- for (var i = 0; i < columns.length; i++) {
- this.columnsX.push(findPosX(columns[i]));
- }
- this.groupsY = [];
- for (var i = 0; i < groups.length; i++) {
- this.groupsY.push([findPosY(groups[i]), groups[i].column]);
- }
- }
- item.onDrag = function (left, top, mouseX, mouseY) {
- if (this.lock) {
- return
- }
- //先要判断在哪一列移动
- var columnIndex = 0;
- for (var i = 0; i < this.columnsX.length; i++) {
- if ((findPosX(this) + this.offsetWidth / 2) > this.columnsX[i]) {
- columnIndex = i;
- }
- }
- var column = columns[columnIndex];
- var groupIndex = null;
- //选择group
- for (var i = 0; i < this.groupsY.length; i++) {
- if (this.groupsY[i][1] == column) {
- if (column.id == "keys") {
- if ($(groups[i]).hasClass("selected")) {
- groupIndex = i;
- }
- } else if (column.id == "candidate") {
- groupIndex = i;
- }
- }
- }
- var group = groups[groupIndex];
- if (this.group != group) {
- this.group = group;
- // group.appendChild(dragGhost);
- group.items.appendChild(dragGhost);
- }
- var currentNode = null;
- for (var i = 0; i < this.group.items.childNodes.length; i++) {
- // var item=this.group.childNodes[i];
- var tempitem = this.group.items.childNodes[i];
- // if(item.className=="item"
- // &&item!=this
- // &&top<findPosY(item)){
- // currentNode=item;
- // }
- if (tempitem.className == "item" && tempitem != this && findPosY(this) < findPosY(tempitem) && findPosX(this) < findPosX(tempitem)) {
- // console.log(groupIndex+" " + i+" "+findPosY(tempitem));
- currentNode = tempitem
- break
- }
- }
- if (currentNode) {
- // this.group.insertBefore(dragGhost,currentNode);
- this.group.items.insertBefore(dragGhost, currentNode);
- } else { //拖到最下边 没有任何一个元素的上边距比拖动元素的top大 则添加到列的最后
- // this.group.appendChild(dragGhost);
- this.group.items.appendChild(dragGhost)
- }
- }
- item.onDragEnd = function (left, top, mouseX, mouseY) {
- if (this.lock) {
- return
- }
- this.style.opacity = "1";
- this.style.filter = "alpha(opacity=100)";
- // this.group.insertBefore(this,dragGhost);
- this.group.items.insertBefore(this, dragGhost);
- this.style.position = "static";
- this.style.display = "block";
- // this.style.width = "80%";
- this.style.width = "auto";
- dragGhost.style.display = "none";
- }
- //返回true无法拖动
- //false 可拖动
- item.lockDrag = function () {
- console.info("<<<<<<<>>>>>3");
- //没有选中
- if ($("#keys .selected").length == 0) {
- console.log("no selected");
- return true;
- }
- //其他未选中的,同时拖动被初始化,无法拖动
- if (this.parentNode.parentNode.parentNode.id == "keys" && !$(this.parentNode.parentNode).hasClass("selected")) {
- return true;
- }
- return false;
- }
- }
- function setKeyConfirm(thisDiv) {
- console.info("<<<<<<<>>>>>2");
- var URL = document.getElementById("saveURL").value
- var datass = document.getElementById("jsonData").innerHTML;
- if (datass.length == 0) {
- datass = '{nodes:{},lines:{}}'
- }
- var alldata = eval("(" + datass + ")")
- var objectKey;
- if (alldata.objectKey) {
- objectKey = alldata.objectKey
- } else {
- objectKey = []
- }
- var key = {}
- var data = {}
- var codebook = {}
- var temp = {}
- var temp2 = []
- var inputName = document.getElementById("inputName").value;
- var inputDesc = document.getElementById("inputDesc").value;
- var submitName = document.getElementById("submitName").value;
- var showName = document.getElementById("showName").value;
- var bgmbid = document.getElementById("bgmbid") ? document.getElementById("bgmbid").value : null;
- // submitName=inputName
- if (inputName.length == 0||submitName.length==0) {
- alert("名称和申请名称不能为空")
- return;
- }
- var version = 0;
- for (var i = 0; i < objectKey.length; i++) {
- var v = parseInt(objectKey[i].version);
- if (v >= version) {
- version = v;
- }
- }
- version++;
- temp2 = parseTabToJson()
- console.log(temp2)
- temp.name = inputName;
- temp.desc = inputDesc;
-
- temp.submitName = submitName
- temp.codebooks = temp2;
- temp.version = version;
- temp.nodes = {}
- temp.lines = {}
- if (bgmbid) {
- temp.bgmbid = bgmbid
- }
- if(showName){
- temp.showName=showName;
- }
- // alert(objectKey.length)
- objectKey.push(temp)
- console.log(objectKey)
- // return;
- $.post(URL, {
- "fileName": document.getElementById("fileName").value,
- "objectKey": JSON.stringify(objectKey)
- }, function (result) {
- // alert(result)
- if (result.indexOf("保存成功") != -1) {
- //刷新设计页面,关闭窗口
- wd.display.showMsgPopup(result);
- // wd.display.getwdDialogOpener().frames[0].location.reload();
- wd.display.getwdDialogOpener().location.reload();
- wd.display.closeDialog();
- } else {
- alert(result)
- }
- })
- }
- function alterKeyConfirm(thisdiv) {
- console.info("<<<<<<<>>>>>1");
- var URL = document.getElementById("saveURL").value
- var datass = document.getElementById("jsonData").innerHTML;
- if (datass.length == 0) {
- datass = '{nodes:{},lines:{}}'
- }
- var alldata = eval("(" + datass + ")")
- var objectKey;
- if (alldata.objectKey) {
- objectKey = alldata.objectKey
- } else {
- objectKey = [];
- }
- var key = {}
- var data = {}
- var codebook = {}
- var temp = {}
- var temp2 = []
- var inputName = document.getElementById("inputName").value;
- var inputDesc = document.getElementById("inputDesc").value;
- var submitName = document.getElementById("submitName").value;
- var showName = document.getElementById("showName").value;
- var bgmbid = document.getElementById("bgmbid") ? document.getElementById("bgmbid").value : null;
- // submitName=inputName
- var version = $("#version").val();
- if (inputName.length == 0||submitName.length==0) {
- alert("名称和申请名称不能为空");
- return;
- }
- var code = parseTabToJson()
- console.log(code)
- // return
- temp.name = inputName;
- temp.desc = inputDesc;
- temp.codebooks = temp2;
- for (var i = 0; i < objectKey.length; i++) {
- if (objectKey[i].version == version) {
- objectKey[i].name = inputName;
-
- objectKey[i].submitName = submitName;
- if(showName){
- objectKey[i].showName = showName;
- }else{
- delete objectKey[i].showName;
- }
-
-
-
- objectKey[i].desc = inputDesc;
- objectKey[i].codebooks = code;
- if (bgmbid) {
- objectKey[i].bgmbid = bgmbid
- } else {
- delete objectKey[i].bgmbid;
- }
- // if(showName){
- // objectKey[i].showName=showName;
- // }else{
- // delete objectKey[i].showName;
- // }
-
- console.log(objectKey[i])
- }
- }
- $.post(URL, {
- "fileName": document.getElementById("fileName").value,
- "objectKey": JSON.stringify(objectKey)
- }, function (result) {
- // alert(result);
- if (result.indexOf("保存成功") != -1) {
- //刷新设计页面,关闭窗口
- wd.display.showMsgPopup(result);
- // window.location.reload();
- wd.display.getwdDialogOpener().frames[0].location.reload();
- // wd.display.getwdDialogOpener().location.reload();
- wd.display.closeDialog();
- } else {
- alert(result)
- }
- })
- }
- function parseTabToJson() {
- console.info("<<<<<<<>>>>>0");
- var result = [];
- // $("#keys .items").each(function (index, element) {
- // var templist = []
- // $(element).children(".item").each(function (ind, ele) {
- // // <div class="codebook" codebook="${item.codebook}" name="${item.name}" value="${codebookKey}" desc="${item.desc}" html="${codebookValue}">${codebookValue}</div>
- // // </codebook:iterate>
- // var code = {};
- // code.codebook = ele.getAttribute("codebook");
- // code.name = ele.getAttribute("name");
- // code.value = ele.getAttribute("value");
- // code.desc = ele.getAttribute("desc");
- // code.html = ele.getAttribute("html");
- // templist.push(code);
- // })
- // // if(templist.length>0){
- // result.push(templist);
- // // }
- // })
-
- var selectedList=DM.getDrager().selectedList.getAllItems()
- var allItems={};
- for(var i=0;i<selectedList.length;i++){
- var item=selectedList[i];
- var id=item.id;
- var pid=item.parentid;
- if(!pid){
- allItems[id]=[];
- }
- }
- for(var i=0;i<selectedList.length;i++){
- var item=selectedList[i];
- var id=item.id;
- var pid=item.parentid;
- if(pid){
- allItems[pid].push(item);
- }
- }
- console.log(allItems);
-
- for(var key in allItems){
- var templist = [];
-
- for(var i=0;i<allItems[key].length;i++){
- var ele=allItems[key][i].element.querySelector(".receiveCodebook");
- var code = {};
- code.objName = ele.getAttribute("objName"); // 再增加,<key 字段的对象名,增加支持 <key 字段不在流程的对象里 -- 支持单独提交 二级对象,不聚合到一级对象。Lin
- code.codebook = ele.getAttribute("codebook");
- code.name = ele.getAttribute("name");
- code.value = ele.getAttribute("value");
- code.desc = ele.getAttribute("desc");
- code.html = ele.getAttribute("html");
- templist.push(code);
-
-
- }
-
-
- if(templist.length>0){
- result.push(templist);
- }
-
- }
-
-
- return result
- }
- function settingItemMessage(item) {
- if(true)return
-
-
- var codebookname = item.getAttribute("codebook");
- var codebookvalue = item.getAttribute("value");
- var version = $("#version").val();
- var datass = document.getElementById("jsonData").innerHTML;
- if (datass.length == 0) {
- datass = '{nodes:{},lines:{}}'
- }
- var alldata = eval("(" + datass + ")")
- var objectKey;
- if (alldata.objectKey) {
- objectKey = alldata.objectKey
- } else {
- objectKey = [];
- }
- for (var i = 0; i < objectKey.length; i++) {
- var objectname = objectKey[i].name;
- var codebooks = objectKey[i]["codebooks"];
- if (version == objectKey[i].version) {
- continue
- }
- if ((function () {
- if (codebooks && codebooks.length == 0)
- return false;
- for (var j = 0; codebooks && j < codebooks.length; j++) {
- if (codebooks[j].length == 0)
- continue;
- var codebookname2 = codebooks[j][0].codebook;
- if (codebookname2 == codebookname) {
- for (var k = 0; k < codebooks[j].length; k++) {
- if (codebooks[j][k].value == codebookvalue) {
- return true;
- }
- }
- }
- }
- })()) {
- $(item).append("<span class=\"useobject\" style=\"color:red;\">(" + objectname + ")</span>");
- }
- }
- }
- function changeComponentName(ele){
- window.location.href=document.getElementById("setObjectKeyURL").value+"&fileName="+ele.value;
- }
|