+
+
+
+
+
+
+
+ ARSimulation
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/assets/cube.obj b/app/src/main/assets/cube.obj
new file mode 100644
index 0000000..198b6a0
--- /dev/null
+++ b/app/src/main/assets/cube.obj
@@ -0,0 +1,40 @@
+# Blender v2.78 (sub 0) OBJ File: 'cube.blend'
+# www.blender.org
+mtllib cube.mtl
+o Cube
+v 0.010000 -0.010000 -0.010000
+v 0.010000 -0.010000 0.010000
+v -0.010000 -0.010000 0.010000
+v -0.010000 -0.010000 -0.010000
+v 0.010000 0.010000 -0.010000
+v 0.010000 0.010000 0.010000
+v -0.010000 0.010000 0.010000
+v -0.010000 0.010000 -0.010000
+vt 0.3756 0.5006
+vt 0.6244 0.5006
+vt 0.6244 0.7494
+vt 0.3756 0.7494
+vt 0.3756 0.2519
+vt 0.3756 0.0031
+vt 0.6244 0.0031
+vt 0.6244 0.2519
+vt 0.8731 0.7494
+vt 0.8731 0.9981
+vt 0.6244 0.9981
+vt 0.3756 0.9981
+vt 0.1269 0.9981
+vt 0.1269 0.7494
+vn 0.0000 -1.0000 0.0000
+vn 0.0000 1.0000 0.0000
+vn 1.0000 0.0000 0.0000
+vn -0.0000 -0.0000 1.0000
+vn -1.0000 -0.0000 -0.0000
+vn 0.0000 0.0000 -1.0000
+usemtl Material
+s off
+f 1/1/1 2/2/1 3/3/1 4/4/1
+f 5/5/2 8/6/2 7/7/2 6/8/2
+f 1/1/3 5/5/3 6/8/3 2/2/3
+f 2/9/4 6/10/4 7/11/4 3/3/4
+f 3/3/5 7/11/5 8/12/5 4/4/5
+f 5/13/6 1/14/6 4/4/6 8/12/6
diff --git a/app/src/main/assets/cube_cyan.png b/app/src/main/assets/cube_cyan.png
new file mode 100644
index 0000000..8b4f55f
Binary files /dev/null and b/app/src/main/assets/cube_cyan.png differ
diff --git a/app/src/main/assets/cube_green.png b/app/src/main/assets/cube_green.png
new file mode 100644
index 0000000..d29cf0b
Binary files /dev/null and b/app/src/main/assets/cube_green.png differ
diff --git a/app/src/main/assets/index.html b/app/src/main/assets/index.html
index dcde1b2..a217011 100644
--- a/app/src/main/assets/index.html
+++ b/app/src/main/assets/index.html
@@ -142,6 +142,7 @@
+
';
+ console.log(tmpStr);
+ return tmpStr;
+ }
+ if(definedSqlTypes[i]["code"]=="geometry"){
+ console.log("CID: "+cid+" select type from mm4me_gc where f_table_schema||'_'||f_table_name = (select name from mm4me_tables where id="+cid+") ")
+ var geoType=getGeometryType("(select replace(name,'.','_') from mm4me_tables where id="+cid+")");
+ var viewb='
'+window.Android.translate("view_on_map")+'';
+ var res='
';
+ if(geoType=='POINT' || geoType=='MULTIPOINT' )
+ return res+'
'+window.Android.translate("use_gps")+''+
+ '
GPS Informations Type Coords '+
+ '';
+ else if(geoType=='LINESTRING' || geoType=='MULTILINESTRING' )
+ return res+'
'+window.Android.translate("drawl_gps")+''+
+ '
'+window.Android.translate("drawlm_gps")+''+
+ '
'+viewb+'
';
+ else if(geoType=='POLYGON' || geoType=='MULTIPOLYGON' )
+ return res+'
'+window.Android.translate("drawp_gps")+''+
+ '
'+window.Android.translate("drawpm_gps")+''+
+ '
'+viewb+'
';
+
+ }
+ if(definedSqlTypes[i]["code"]=="tbl_linked"){
+ var tmp=obj["value"].split(';');
+ //console.log(cleanupTableName('SELECT '+tmp[1]+' FROM '+tmp[2]+' WHERE '+tmp[0]+'='+tblName+'.id'));
+ var refs=JSON.parse(window.Android.displayTable(cleanupTableName(tmp[3]),[]));
+ var tmpStr='
';
+ for(var j in refs){
+ var cnt=0;
+ tmpStr+="';
+ else
+ if(cnt==1)
+ tmpStr+=refs[j][k];
+ cnt+=1;
+ }
+ tmpStr+=" "
+ }
+ return tmpStr+" ";
+
+ }
+ if(definedSqlTypes[i]["code"]=="link"){
+ var strReturn;
+ if(!View_template)
+ $.ajax({
+ async: false,
+ method: "GET",
+ url: './content/view_template.html',
+ error: function(){
+ console.log("Nothing to run after");
+ },
+ success: function(data){
+ console.log("**** \n\n Load View Template");
+ View_template=data;
+ var tmp=obj["value"].split(";");
+ var refs=JSON.parse(window.Android.displayTable("SELECT mm4me_tables.id as tid,mm4me_views.id as id,mm4me_tables.name as name,mm4me_tables.description,mm4me_views.name as title from mm4me_tables,mm4me_views where mm4me_tables.name=\""+tmp[1]+"\" and mm4me_tables.id=mm4me_views.ptid",[]));
+ var reg=new RegExp("\\[id\\]","g");
+ if(!valuesOnLoad[cid])
+ valuesOnLoad[cid]=[];
+ if(refs!=""){
+ valuesOnLoad[cid].push(refs);
+ if(!toRunOnLoad[cid])
+ toRunOnLoad[cid]=[];
+ toRunOnLoad[cid].push(function(){
+ prefix="_"+arguments[0]["0"]["id"];
+ //if(!mainTable[arguments[0]["0"]["id"]])
+ //mainTable[arguments[0]["0"]["id"]]=arguments[0]["0"]["tid"];
+ //console.log(arguments[0]["0"]["tid"]+" "+arguments[0]["0"]["name"]+" "+arguments[0]["0"]["title"]);
+ listInnerTable(arguments[0]["0"]["tid"],arguments[0]["0"]["id"],arguments[0]["0"]["name"],arguments[0]["0"]["title"],false,prefix,tmp[0]+"="+arguments[1]["local_id"]);
+ });
+ refTables[refs["0"]["tid"]]={"oid":cid,"col":tmp[0],"vid":refs["0"]["id"],"name":refs["0"]["table"],"name":refs["0"]["title"]};
+ strReturn=data.replace(reg,refs["0"]["tid"]);
+ }
+ }
+ });
+ else{
+ var tmp=obj["value"].split(";");
+ var refs=JSON.parse(window.Android.displayTable("SELECT mm4me_tables.id as tid,mm4me_views.id as id,mm4me_tables.name as name,mm4me_tables.description,mm4me_views.name as title from mm4me_tables,mm4me_views where mm4me_tables.name=\""+tmp[1]+"\" and mm4me_tables.id=mm4me_views.ptid",[]));
+ var reg=new RegExp("\\[id\\]","g");
+ if(!valuesOnLoad[cid])
+ valuesOnLoad[cid]=[];
+ valuesOnLoad[cid].push(refs);
+ if(!toRunOnLoad[cid])
+ toRunOnLoad[cid]=[];
+ toRunOnLoad[cid].push(function(){
+ prefix="_"+arguments[0]["0"]["id"];
+ //if(!mainTable[arguments[0]["0"]["id"]])
+ //mainTable[arguments[0]["0"]["id"]]=arguments[0]["0"]["tid"];
+ //console.log(arguments[0]["0"]["tid"]+" "+arguments[0]["0"]["name"]+" "+arguments[0]["0"]["title"]);
+ listInnerTable(arguments[0]["0"]["tid"],arguments[0]["0"]["id"],arguments[0]["0"]["name"],arguments[0]["0"]["title"],false,prefix,tmp[0]+"="+arguments[1]["local_id"]);
+ });
+ refTables[refs["0"]["tid"]]={"oid":cid,"col":tmp[0],"vid":refs["0"]["id"],"name":refs["0"]["table"],"name":refs["0"]["title"]};
+ strReturn=View_template.replace(reg,refs["0"]["tid"]);
+
+ }
+ //console.log(strReturn);
+ return strReturn;
+ }
+ if(definedSqlTypes[i]["code"]=="ref"){
+ var req=obj["value"];//.replace(/^\((\w+)\)$/g,"$1");
+ if(req[0]=="(")
+ req="SELECT * FROM "+req;
+ var refs=JSON.parse(window.Android.displayTable(cleanupTableName(req),[]));
+ var tmpStr='
';
+ var cvalues=[];
+ //console.log(JSON.stringify(refs));
+ for(var j=0;j';
+ cStr+='value="'+refs[j][k]+'">';
+ cvalues.push(refs[j][k]);
+ }
+ else
+ if(cnt==1)
+ //tmpStr+=refs[j][k];
+ cStr+=refs[j][k];
+ cnt+=1;
+ }
+ //tmpStr+=""
+ cStr+="";
+ if(cnt==1){
+ for(var k in refs[j]){
+ cStr=''+refs[j][k]+' ';
+ }
+ }
+ tmpStr+=cStr;
+ }
+ tmpStr+=" ";
+
+ if(obj["dependencies"])
+ try{
+ var lobj={};
+ lobj[obj["id"]]={"dep":JSON.parse(obj["dependencies"])};
+ for(var jj=0;jj
=0){
+ return ' ';
+ }
+ if(definedSqlTypes[i]["code"]=="html")
+ return '';
+ if(definedSqlTypes[i]["code"]=="text")
+ return '';
+ if(definedSqlTypes[i]["code"]=="boolean")
+ return ' ';
+ if(definedSqlTypes[i]["code"]=="date" || definedSqlTypes[i]["code"]=="datetime")
+ return ' ';
+ if(definedSqlTypes[i]["code"]=="float")
+ return ' ';
+ return definedSqlTypes[i]["code"];
+ }
+ }
+ return null;
+}
+
+function printOptionalCheckbox(obj,cid){
+ if(definedSqlTypes.length==0){
+ definedSqlTypes=JSON.parse(window.Android.displayTable("select id,code from mm4me_ftypes where ftype='e' order by name",[]));
+ }
+
+ var res=' ';
+ for(var i in definedSqlTypes){
+ if(definedSqlTypes[i]["id"]==obj["ftype"]){
+ if(definedSqlTypes[i]["code"]=="bytea"){
+ var tmpStr="";
+ return res;
+ }
+ else if(definedSqlTypes[i]["code"]=="geometry"){
+ return res
+ }
+ }
+ }
+ return '';
+}
+
+var refTypeId=null;
+var editPrintedOnce=[];
+/*****************************************************************************
+ * Create HTML part to display the line containing both the title and the
+ * corresponding input for a given table's field.
+ *****************************************************************************/
+function printEditionFields(obj,myRoot,cid,mid){
+ var list1=window.Android.displayTable("select * from mm4me_edition_fields where mm4me_edition_fields.edition>0 and eid="+obj["id"]+" order by mm4me_edition_fields.id asc",[]);
+ if(!editSchema[mid])
+ editSchema[mid]={};
+ editSchema[mid][obj["id"]]=JSON.parse(list1);
+ list1=JSON.parse(list1);
+ myRoot.find(".tab-content").first().append(''+obj["description"]+'
');
+ for(var j in list1)
+ if(list1[j]["edition"]>0) {
+ myRoot.find(".tab-content").first().children().last().append(
+ '');
+ if(list1[j]["dependencies"]){
+ try{
+ editPrintedOnce.push(list1[j]["name"]);
+ console.log("JSON PARSE")
+ console.log(list1[j]["dependencies"]);
+ var objJson=JSON.parse(list1[j]["dependencies"]);
+ console.log("JSON PARSE OK");
+ if(!refTypeId)
+ refTypeId=JSON.parse(window.Android.displayTable("select id from mm4me_ftypes where ftype='e' and code='ref'",[]))[0]["id"];
+ console.log(refTypeId);
+ for(i in objJson){
+ if(objJson[i]["myself"]){
+ console.log("IS MYSELF!!");
+ for(k in objJson[i]["myself"]){
+ for(l in objJson[i]["myself"][k]){
+
+
+ if(objJson[i]["myself"][k][l]["dependents"]){
+ for(m in objJson[i]["myself"][k][l]["dependents"]){
+ for(n in objJson[i]["myself"][k][l]["dependents"][m]){
+ console.log(objJson[i]["myself"][k][l]["dependents"][m][n]["sql_query"]);
+ console.log(objJson[i]["myself"][k][l]["dependents"][m][n]["label"]);
+ var lObj={"id": n, "ftype":refTypeId,"value":objJson[i]["myself"][k][l]["dependents"][m][n]["sql_query"]};
+ //if(!myRoot.find('select[name="field_'+list1[j]["id"]+'"]').parent().find('select[name="field_'+n+'"]').length)
+ myRoot.find('select[name="field_'+list1[j]["id"]+'"]').last().parent().prepend(
+ '');
+ console.log(myRoot.find('select[name="field_'+n+'"]'));
+ console.log(printCurrentType(lObj,mid));
+ (function(a,b){
+ myRoot.find('select[name="field_'+n+'"]').off('change');
+ myRoot.find('select[name="field_'+n+'"]').on('change',function(){
+ console.log('select[name="field_'+n+'"]');
+ var req=cleanupTableName(a["value"]);
+ if(a["value"].indexOf("WHERE")<0){
+ req=req.replace(/order by/g,"where "+b["tfieldf"]+" "+b["operator"]+" "+(b["operator"]=="like"?"'":"")+$(this).val()+(b["operator"]=="like"?"'":"")+" order by")
+ }
+ console.log(req);
+ var res=JSON.parse(window.Android.displayTable(req,[]));
+ myRoot.find('select[name="field_'+a["id"]+'"]').html("");
+ for(ij in res){
+ var tmpStr=' ';
+ else{
+ tmpStr+=res[ij][kl]+'';
+ myRoot.find('select[name="field_'+a["id"]+'"]').append(tmpStr);
+ }
+ poi+=1;
+ }
+ }
+
+ })
+ })(list1[j],objJson[i]["myself"][k][l]["dependents"][m][n]);
+
+ }
+ }
+ }
+
+ console.log(objJson[i]["myself"][k][l]["sql_query"]);
+ console.log(objJson[i]["myself"][k][l]["label"]);
+ var lObj={"id": l,"ftype":refTypeId,"value":objJson[i]["myself"][k][l]["sql_query"]};
+ //if(!myRoot.find('select[name="field_'+list1[j]["id"]+'"]').parent().find('select[name="field_'+l+'"]').length)
+ myRoot.find('select[name="field_'+list1[j]["id"]+'"]').last().parent().prepend(
+ '');
+ console.log(myRoot.find('select[name="field_'+l+'"]'));
+ console.log('select[name="field_'+l+'"]');
+ (function(a,b,c,d,e){
+ myRoot.find('select[name="field_'+a+'"]').on('change',function(){
+ console.log('select[name="field_'+a+'"]');
+ if(b["dependents"]){
+ for(m in b["dependents"]){
+ for(n in b["dependents"][m]){
+ var req=cleanupTableName(b["dependents"][m][n]["sql_query"]);
+ if(req.indexOf("WHERE")<0)
+ req=req.replace(/order by/g," WHERE "+b["tfield"]+" "+b["operator"]+" "+(b["operator"]=="like"?"'":"")+$(this).val()+(b["operator"]=="like"?"'":"")+" order by ");
+ var res=JSON.parse(window.Android.displayTable(req,[]));
+ myRoot.find('select[name="field_'+n+'"]').html("");
+ for(ij in res){
+ var tmpStr=' ';
+ else{
+ tmpStr+=res[ij][kl]+'';
+ myRoot.find('select[name="field_'+n+'"]').append(tmpStr);
+ }
+ poi+=1;
+ }
+ }
+ myRoot.find('select[name="field_'+n+'"]').change();
+ }
+ }
+ }else{
+ var req=cleanupTableName(c["value"]);
+ var clause=b["tfield"]+" "+b["operator"]+" "+(b["operator"]=="like"?"'":"")+$(this).val()+(b["operator"]=="like"?"'":"");
+ if(d.length>1){
+ for(var i=0;i';
+ else{
+ tmpStr+=res1[ij1][kl1]+'';
+ myRoot.find('select[name="field_'+c["id"]+'"]').append(tmpStr);
+ }
+ poi+=1;
+ }
+ }
+ if(b["html_template"]){
+ myRoot.find('select[name="field_'+c["id"]+'"]').off('change');
+ myRoot.find('select[name="field_'+c["id"]+'"]').on('change',function(){
+ if(!$(this).parent().find(".html_layout"))
+ $(this).parent().append('
');
+
+ });
+ }
+ }catch(e){console.log(e);}
+ console.log(req);
+ }
+ });
+ })(l,objJson[i]["myself"][k][l],list1[j],objJson[i]["myself"],k);
+
+ //if(objJson[i]["myself"][k][l]["dependents"])
+ myRoot.find('select[name="field_'+l+'"]').change();
+
+ }
+ }
+ }else
+ console.log("Basic dependencies!");
+ }
+ }catch(e){
+ console.log(e);
+ }
+ }
+
+
+ }
+
+ myRoot.find(".tab-content").first().children().last().append(
+ ''+
+ ''+window.Android.translate((cid.indexOf('_')<0?'save':'add'))+' '+
+ '
');
+ console.log(JSON.stringify(currentTypes));
+ for(i in currentTypes){
+ console.log(currentTypes[i]);
+ $("#edition_form_"+cid).find("#"+currentTypes[i]).change();
+ }
+ myRoot.show();
+}
+
+/*****************************************************************************
+ * Execute an Insert SQL query for a given table
+ *****************************************************************************/
+function runInsertQuery(obj,mid,func){
+ if(MM4ME_DEBUG)
+ console.log($(obj).attr('id')+" "+mid);
+ var query="INSERT INTO "+cleanupTableName(allTables[mid].name);
+ var queryAttr=[];
+ var queryValues0=[];
+ var queryValues=[];
+ var queryTypes=[];
+ $(obj).find("input,select,textarea").each(function(){
+ if(MM4ME_DEBUG)
+ console.log($(this).attr("name")+" <> "+$(this).val());
+ try{
+
+ var cid=$(this).attr("name").replace(/field_/g,"");
+ console.log(!$("#"+cid+"_display").length || ($("#"+cid+"_display").length && $("#"+cid+"_display").is(":checked")));
+ var found=false;
+ if((!$("#"+cid+"_display").length || ($("#"+cid+"_display").length && $("#"+cid+"_display").is(":checked"))))
+ for(var i in editSchema[mid]){
+ for(var j in editSchema[mid][i]){
+ if(editSchema[mid][i][j]["id"]==cid){
+ if(editSchema[mid][i][j]["name"].indexOf("unamed")<0 && $(this).parent().is(":visible")){
+ if(MM4ME_DEBUG)
+ console.log(editSchema[mid][i][j]["name"]+" <> "+$(this).val());
+ queryAttr.push(editSchema[mid][i][j]["name"].replace(/wkb_geometry/g,"geometry"));
+ queryValues.push($(this).val());
+ queryValues0.push("?");
+ queryTypes.push(parseInt(editSchema[mid][i][j]["ftype"]));
+ }
+ found=true;
+ break;
+ }
+ }
+ if(found)
+ break;
+ }
+ }catch(e){
+ console.log(e);
+ }
+ });
+ var regs=[
+ new RegExp("\\[","g"),
+ new RegExp("\\]","g")
+ ];
+
+ for(var i in editSchema[mid]){
+ for(var j in editSchema[mid][i]){
+ if(editSchema[mid][i][j]["ftype"]==EDITION_TYPE_FILE && $("#"+editSchema[mid][i][j]["id"]+"_display").length && $("#"+editSchema[mid][i][j]["id"]+"_display").is(":checked") ){
+ queryAttr.push(editSchema[mid][i][j]["name"]);
+ queryValues0.push("?");
+ queryTypes.push(parseInt(editSchema[mid][i][j]["ftype"]));
+ queryValues.push($(obj).find("#value_"+editSchema[mid][i][j]["id"]).find("img").attr("src"));
+ //subquery+=",readfile('"+$(obj).find("#value_"+editSchema[mid][i][j]["id"]).find("img").attr("src")+"')";
+ }
+ }
+ }
+
+ var ccol=getPKey(cleanupTableName(allTables[mid].name));
+ queryAttr.push(ccol);
+ var osubquery=("(select max("+ccol+") from "+cleanupTableName(allTables[mid].name)+")");
+ var subquery=("(select CASE WHEN count(*) > 0 THEN max("+ccol+")+1 ELSE 1 END from "+cleanupTableName(allTables[mid].name)+")");
+ if(refTables[mid]){
+ queryAttr.push(refTables[mid]["col"]);
+ subquery+=","+referenceIds[mtable];
+ }
+
+ //var req=(query+" ("+queryAttr.join(",")+") VALUES "+JSON.stringify(queryValues,null).replace(regs[0],"(")+"");
+ var req=(query+" ("+queryAttr.join(",")+") VALUES ("+queryValues0.join(",")+","+subquery+")");
+ if(MM4ME_DEBUG){
+ console.log(req);
+ console.log(queryTypes);
+ }
+ var res=window.Android.executeQuery(req,queryValues,queryTypes);
+ window.Android.executeQuery("INSERT INTO history_log (tbl,sql,pkey_value) VALUES (?,?,"+osubquery+")",[cleanupTableName(allTables[mid].name),req],[1,1]);
+ try{
+ window.Android.showToast(window.Android.translate("insert_success"));
+ func(mid);
+ }catch(e){
+ window.Android.notify("Error: "+e);
+ }
+
+}
+
+var systemSelectedIndex=-1;
+/*****************************************************************************
+ * Execute an Update SQL query for a given table
+ *****************************************************************************/
+function runUpdateQuery(obj,mid,func){
+ var query="UPDATE "+cleanupTableName(allTables[mid].name)+" set ";
+ var queryAttr=[];
+ var queryValues0=[];
+ var queryValues=[];
+ var queryTypes=[];
+ var lastValue=$("#exampleTable"+((mid==mtable)?"":"_"+mid)).find(".selected").find('input[type=hidden]').first().val()?$("#exampleTable"+((mid==mtable)?"":"_"+mid)).find(".selected").find('input[type=hidden]').first().val():systemSelectedIndex;
+ var ccol=getPKey(cleanupTableName(allTables[mid].name));
+ var queryEnd=" WHERE "+ccol+"=?";
+ var lcnt=0;
+ $(obj).find("input,select,textarea").each(function(){
+ if(MM4ME_DEBUG)
+ console.log($(this).attr("name")+" <> "+$(this).val());
+ try{
+ var cid=$(this).attr("name").replace(/field_/g,"");
+ console.log($(this).parent().is(":visible"));
+ var found=false;
+ if($(this).parent().is(":visible") || $(this).is(":visible"))
+ for(var i in editSchema[mid]){
+ for(var j in editSchema[mid][i]){
+ if(editSchema[mid][i][j]["id"]==cid){
+ if(editSchema[mid][i][j]["name"].indexOf("unamed")<0){
+ //console.log(JSON.stringify(editSchema[mid][i][j]));
+ if(MM4ME_DEBUG)
+ console.log(editSchema[mid][i][j]["name"]+" <> "+$(this).val());
+ query+=(lcnt>0?", ":"")+editSchema[mid][i][j]["name"].replace(/wkb_geometry/g,"geometry")+"=?";
+ queryTypes.push(parseInt(editSchema[mid][i][j]["ftype"]));
+ queryValues.push($(this).val());
+ //query+=(lcnt>0?", ":"")+editSchema[mid][i][j]["name"]+"="+JSON.stringify($(this).val(),null);
+ //queryAttr.push(editSchema[i][j]["name"]);
+ //queryValues.push($(this).val());
+ lcnt+=1;
+ }
+ found=true;
+ break;
+ }
+ }
+ if(found)
+ break;
+ }
+ }catch(e){
+ console.log(e);
+ }
+ });
+ for(var i in editSchema[mid]){
+ for(var j in editSchema[mid][i]){
+ if(editSchema[mid][i][j]["ftype"]==EDITION_TYPE_FILE && $(obj).find("#value_"+editSchema[mid][i][j]["id"]).find("img").length && $("#"+editSchema[mid][i][j]["id"]+"_display").length && $("#"+editSchema[mid][i][j]["id"]+"_display").is(":checked") ){
+ //queryAttr.push(editSchema[mid][i][j]["name"]);
+ query+=(lcnt>0?", ":"")+editSchema[mid][i][j]["name"]+"=?";
+ queryTypes.push(parseInt(editSchema[mid][i][j]["ftype"]));
+ queryValues.push($(obj).find("#value_"+editSchema[mid][i][j]["id"]).find("img").attr("src"));
+ //subquery+=",readfile('"+$(obj).find("#value_"+editSchema[mid][i][j]["id"]).find("img").attr("src")+"')";
+ lcnt+=1;
+ }
+ }
+ }
+
+ queryValues.push(lastValue);
+ queryTypes.push(lastValue,1);
+ var req=query+queryEnd;
+ if(MM4ME_DEBUG)
+ console.log(req);
+ if(window.Android.executeQuery(req,queryValues,queryTypes)>=0){
+ window.Android.executeQuery("INSERT INTO history_log (tbl,sql,pkey_value) VALUES (?,?,?)",[cleanupTableName(allTables[mid].name),req,lastValue],[1,1,1]);
+ window.Android.showToast(window.Android.translate("update_success"));
+ func(mid);
+ }
+}
+
+/*****************************************************************************
+ * Get the table's primary key, stored in the primary_keys table
+ *****************************************************************************/
+function getPKey(tbl){
+ var req0="SELECT col FROM primary_keys where tbl='"+tbl+"'";
+ if(MM4ME_DEBUG)
+ console.log(req0);
+ var list01=JSON.parse(window.Android.displayTable(req0,[]));
+ if(MM4ME_DEBUG)
+ console.log(JSON.stringify(list01[0]));
+ return list01[0]["col"];
+}
+
+/*****************************************************************************
+ * Get the geometry type, stored in the mm4me_gc table
+ *****************************************************************************/
+function getGeometryType(tbl){
+ var req0="select type from mm4me_gc where f_table_schema||'_'||f_table_name = "+tbl+"";
+ if(MM4ME_DEBUG)
+ console.log(req0);
+ var list01=JSON.parse(window.Android.displayTable(req0,[]));
+ if(MM4ME_DEBUG)
+ console.log(JSON.stringify(list01[0]));
+ return list01[0]["type"];
+}
+
+/*****************************************************************************
+ * The fucntion to call at the end of insert or update query
+ *****************************************************************************/
+function editTableReact(tid){
+ var mid=tid;
+ if(MM4ME_DEBUG)
+ console.log("editTableReact("+mid+')');
+ if(mid==mtable){
+ $('.mm4me_listing').find('ul').first().find('a').first().click();
+ $(".require-select").hide();
+ listTable(allTables[mid].id,tblName,tblTitle,false);
+ }
+ else{
+ $("#sub_tableContent_"+mid).find(".require-select").hide();
+ $("#sub_tableContent_"+mid).find('ul').first().find('a').first().click();
+ listInnerTable(mid,refTables[mid]["vid"],allTables[mid]["name"],refTables[mid]["name"],true,"_"+refTables[mid]["vid"],refTables[mid]["col"]+"="+referenceIds[refTables[mid]["oid"]]);
+ }
+}
+
+/*****************************************************************************
+ * Display the content of the current edited table.
+ *****************************************************************************/
+function listTable(id,name,title,init,prefix){
+ tblId=mainTable[id];
+ tblName=name;
+ tblTitle=title;
+
+ var list=window.Android.displayTable("select mm4me_editions.id,mm4me_editions.name,mm4me_editions.description from mm4me_editions,mm4me_tables where mm4me_editions.ptid=mm4me_tables.id and mm4me_tables.id="+tblId+" and step>=0 order by mm4me_editions.step asc",[]);
+ if(MM4ME_DEBUG)
+ console.log(list);
+ list=JSON.parse(list);
+ if(MM4ME_DEBUG)
+ console.log((!allTables[tblId]));
+ if(!allTables[tblId]){
+ allTables[tblId]={"id":id,"name":name,"title":title};
+ mtable=tblId;
+
+ $(".mm4me_edition").find("ul").first().html("");
+ $(".mm4me_edition").find(".well").first().html("");
+ $(".mm4me_listing").find("ul").first().append(''+window.Android.translate('table')+' ');
+ var cnt=0;
+ for(var i in list){
+ lastEdition[list[i]["id"]]=list[i];
+ $(".mm4me_edition").find("ul").first().append(''+list[i]["name"]+' ');
+ printEditionFields(list[i],$("#edition_form_edit"),list[i]["id"],mainTable[id]);
+ if(cnt==0){
+ try{
+ var cid=list[i]["id"]+"_0";
+ $(".mm4me_listing").find("ul").first().append(''+window.Android.translate('edit')+' ');
+ $(".mm4me_listing").find("ul").first().append(''+window.Android.translate('add')+' ');
+ $(".require-select").hide();
+ printEditionFields(list[i],$(".mm4me_listing"),cid,mainTable[id]);
+ }catch(e){
+ console.log("**** ERROR ***> "+e);
+ }
+ }
+ cnt+=1;
+ }
+ }
+
+ $('.mm4me_listing').find('ul').first().find('a').click(function (e) {
+ e.preventDefault();
+ if($(this).parent().hasClass('require-select'))
+ $('.mm4me_edition').show();
+ else
+ $('.mm4me_edition').hide();
+ if(MM4ME_DEBUG)
+ console.log("DEBUG !! "+$(this).hasClass('require-select'))
+ $(this).tab('show');
+ })
+ $('.mm4me_edition').find('ul').find('a').click(function (e) {
+ e.preventDefault();
+ $(this).tab('show');
+ })
+ $('.mm4me_listing').find('ul').first().find('a').first().click();
+ $('.mm4me_edition').find('ul').find('a').first().click();
+ $('.swagEditor').summernote();
+ $(".mm-act-add").click(function(){
+ runInsertQuery($(this).parent().parent(),mainTable[id],editTableReact);
+ });
+ $(".mm-act-save").click(function(){
+ runUpdateQuery($(this).parent().parent(),mainTable[id],editTableReact);
+ });
+ $(".breadcrumb").children().last().remove();
+ //$('.mm4me_edition').hide();
+
+ var list=window.Android.displayTable("SELECT id,name,value,alias,width,class from mm4me_view_fields where vid="+id+" order by id asc",[]);
+ if(MM4ME_DEBUG)
+ console.log(list);
+ list=JSON.parse(list);
+ var columnNames=[];
+ var columns=[];
+ var sqlColumns="";
+ var orderColumn="id";
+ var orderType="asc";
+ //alert(list);
+ for(var i=0;i0){
+ orderColumn=list[i]["name"];
+ if(list[i]["class"]==1)
+ orderType="desc";
+ }
+ }
+ var ccol=getPKey(cleanupTableName(name));
+ var req="SELECT "+ccol+" as ogc_fid FROM "+cleanupTableName(name)+" ORDER BY "+cleanupTableName(name)+"."+orderColumn+" "+orderType;
+ var list1=JSON.parse(window.Android.displayTable(req,[]));
+ req="SELECT "+sqlColumns+" FROM "+cleanupTableName(name)+" ORDER BY "+cleanupTableName(name)+"."+orderColumn+" "+orderType;
+ var list=JSON.parse(window.Android.displayTable(req,[]));
+ var dataSet = [];
+ if(list)
+ for(var i=0;i ';
+ }
+ if(MM4ME_DEBUG){
+ console.log(JSON.stringify(columnNames));
+ console.log(JSON.stringify(tmpData));
+ }
+ dataSet.push(tmpData);
+ }
+ var selected = [];
+
+ var localName="exampleTable"+(!prefix?"":prefix);
+ ((function(localName,mid){
+ if(init){
+ $(".breadcrumb").append(' '+window.Android.translate('view')+' ');
+ $(".breadcrumb").append(' '+tblTitle+' ');
+
+ var options={
+ data: dataSet,
+ columns: columns,
+ "scrollX": true,
+ scrollY: '50vh',
+ scrollCollapse: true,
+ select: true
+ };
+ if(langUrl!=null)
+ options["language"]={
+ url: langUrl
+ };
+ $('#'+localName).DataTable( options );
+ $('#'+localName+' tbody').on('click', 'tr', function () {
+ var id = this.id;
+ var index = $.inArray(id, selected);
+
+ if ( index === -1 ) {
+ selected.push( id );
+ } else {
+ selected.splice( index, 1 );
+ }
+ displayEditForm(mid,$(this).find("input[name=id]").first().val(),true);
+ var tmp=$(this).hasClass('selected');
+ var closure=$(this);
+ $('#'+localName+' tbody tr').each(function(){$(this).removeClass('selected')});
+ $(this).toggleClass('selected');
+ if(!tmp)
+ $(this).toggleClass('selected');
+ /*else
+ $(this).removeClass('selected');*/
+
+ } );
+ }else{
+ $('#'+localName).dataTable().fnClearTable();
+ $('#'+localName).dataTable().fnAddData(dataSet);
+ }
+ })(localName,mainTable[id]));
+
+ setTimeout(function() { updateChangingFields(changingFields) }, 1500);
+ $('.mm4me_listing').show();
+ $('.mm4me_content').hide();
+}
+
+/*****************************************************************************
+ * Update a field depending on another field value (i.e region > department)
+ *****************************************************************************/
+function updateChangingFields(changingFields){
+ if(MM4ME_DEBUG)
+ console.log(JSON.stringify(changingFields));
+ try{
+ for(var i=0;i';
+ else
+ cStr+=changingField[j][ckey]["values"][cIndex][i][lkey]+' ';
+ cnt+=1;
+ }
+ cnt0+=1;
+ $("select[name=field_"+changingField[j][ckey]["id"]+"]").append(cStr);
+ }
+ if(i==0)
+ $("select[name=field_"+changingField[j][ckey]["id"]+"]").html(''+window.Android.translate('none')+' ');
+ $("select[name=field_"+changingField[j][ckey]["id"]+"]").change();
+ }else{
+ console.log("DISPLAY ELEMENT IF CINDEX >=0 ");
+ //console.log(JSON.stringify(changingField[j][ckey]));
+ console.log('input[name="field_'+ckey+'"],select[name="field_'+ckey+'"],textarea[name="field_'+ckey+'"]');
+ console.log($('input[name="field_'+changingField[j][ckey]["id"]+'"],select[name="field_'+changingField[j][ckey]["id"]+'"],textarea[name="field_'+changingField[j][ckey]["id"]+'"]').parent().parent().html());
+ var mycKey=changingField[j][ckey]["id"];
+ if(cIndex<0)
+ $('input[name="field_'+mycKey+'"],select[name="field_'+mycKey+'"],textarea[name="field_'+mycKey+'"]').parent().parent().hide();
+ else
+ $('input[name="field_'+mycKey+'"],select[name="field_'+mycKey+'"],textarea[name="field_'+mycKey+'"]').parent().parent().show();
+ }
+ }
+ }
+ };
+ };
+ $("select[name=field_"+key+"]").off('change');
+ $("select[name=field_"+key+"]").change(localFunc(changingFields[i][key]["dep"]));
+ $("select[name=field_"+key+"]").change();
+ }
+ }
+ }catch(e){
+ console.log(e);
+ setTimeout(function() { updateChangingFields(changingFields) }, 500);
+ }
+}
+
+/*****************************************************************************
+ * Display the content of a table referencing the current edited table.
+ *****************************************************************************/
+function listInnerTable(id,vid,name,title,init,prefix,clause,ref){
+ var list=JSON.parse(window.Android.displayTable("select mm4me_tables.id as tid,mm4me_tables.name as tname,mm4me_editions.id,mm4me_editions.name from mm4me_editions,mm4me_tables where mm4me_editions.ptid=mm4me_tables.id and mm4me_tables.id="+id+" order by mm4me_editions.step asc",[]));
+ var cnt=0;
+ var detectInit=true;
+ var tid=0;
+ for(var i in list){
+ lastEdition[list[i]["id"]]=list[i];
+ tid=list[i]["tid"];
+ if(!allTables[list[i]["tid"]]){
+ allTables[list[i]["tid"]]={"id":list[i]["id"],"name":list[i]["tname"],"title":list[i]["name"]};
+ detectInit=false;
+ $("#sub_tableContent_"+id+"").find(".mm4me_edition").find("ul").first().append(''+list[i]["name"]+' ');
+ printEditionFields(list[i],$("#sub_tableContent_"+id+"").find(".mm4me_edition"),list[i]["id"],list[i]["tid"]);
+ if(cnt==0){
+ try{
+ var cid=list[i]["id"]+"_0";
+ $("#sub_tableContent_"+id+"").find("ul").first().append(''+window.Android.translate('table')+' ');
+ $("#sub_tableContent_"+id+"").find("ul").first().append(''+window.Android.translate('edit')+' ');
+ $("#sub_tableContent_"+id+"").find("ul").first().append(''+window.Android.translate('add')+' ');
+ $("#sub_tableContent_"+id+" .require-select").hide();
+ printEditionFields(list[i],$("#sub_tableContent_"+id+""),cid,list[i]["tid"]);
+ }catch(e){
+ console.log("**** ERROR ***> "+e);
+ }
+ }
+ var myRoot=$("#sub_tableContent_"+id+"");
+ myRoot.find('ul').first().find('a').click(function (e) {
+ e.preventDefault();
+ if($(this).parent().hasClass('require-select'))
+ myRoot.find('.mm4me_edition').show();
+ else
+ myRoot.find('.mm4me_edition').hide();
+ $(this).tab('show');
+ })
+ myRoot.find('ul').first().find('a').first().click();
+ myRoot.find('.mm4me_edition').find('ul').find('a').first().click();
+ myRoot.find('.swagEditor').summernote();
+ myRoot.find(".mm-act-add").click(function(){
+ runInsertQuery($(this).parent().parent(),tid,editTableReact);
+ });
+ myRoot.find(".mm-act-save").click(function(){
+ runUpdateQuery($(this).parent().parent(),tid,editTableReact);
+ });
+
+ }
+ cnt+=1;
+ }
+
+ var list=JSON.parse(window.Android.displayTable("SELECT id,name,value,alias,width,class from mm4me_view_fields where vid="+vid+" order by id",[]));
+ var columns=[];
+ var columnNames=[];
+ var sqlColumns="";
+ var orderColumn="id";
+ var orderType="asc";
+ for(var i=0;i0){
+ orderColumn=list[i]["name"];
+ if(list[i]["class"]==1)
+ orderType="desc";
+ }
+ }
+ var ccol=getPKey(cleanupTableName(name));
+ var req="SELECT "+ccol+" as ogc_fid FROM "+cleanupTableName(name)+" WHERE "+clause+" ORDER BY "+cleanupTableName(name)+"."+orderColumn+" "+orderType;
+ var list1=JSON.parse(window.Android.displayTable(req,[]));
+ req="SELECT "+sqlColumns+" FROM "+cleanupTableName(name)+" WHERE "+clause+" ORDER BY "+cleanupTableName(name)+"."+orderColumn+" "+orderType;
+ var list=JSON.parse(window.Android.displayTable(req,[]));
+ var dataSet = [];
+ for(var i=0;i ';
+ cnt+=1;
+ }
+ dataSet.push(tmpData);
+ }
+ var selected = [];
+
+ //$("#edition_form_table").html('');
+ var localName="exampleTable_"+id;
+ ((function(localName,sid){
+
+ if(!detectInit){
+
+ var options={
+ data: dataSet,
+ columns: columns,
+ "scrollX": true,
+ scrollY: '50vh',
+ scrollCollapse: true,
+ select: true,
+ "rowCallback": function( row, data ) {
+ if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
+ $(row).addClass('selected');
+ }
+ }
+ };
+ if(langUrl!=null)
+ options["language"]={
+ url: langUrl
+ };
+
+ $('#'+localName).DataTable( options );
+ $('#'+localName+' tbody').on('click', 'tr', function () {
+ var id = this.id;
+ var index = $.inArray(id, selected);
+
+ if ( index === -1 ) {
+ selected.push( id );
+ } else {
+ selected.splice( index, 1 );
+ }
+ displayEditForm(sid,$(this).find("input[name=id]").first().val(),true);
+ var tmp=$(this).hasClass('selected');
+ $('#'+localName+' tbody tr').removeClass('selected');
+ $(this).toggleClass('selected');
+ if(!tmp)
+ $(this).toggleClass('selected');
+ } );
+
+ }else{
+ $('#'+localName).dataTable().fnClearTable();
+ if(dataSet.length>0)
+ $('#'+localName).dataTable().fnAddData(dataSet);
+ }
+ $("#sub_tableContent_"+id+"").find("ul").first().find('a').first().click();
+ })(localName,tid));
+
+}
+
+var onFormFirstLoad=null;
+/*****************************************************************************
+ * Show the edit form
+ *****************************************************************************/
+function displayEditForm(cid,selectedId,basic){
+ if(basic && !$("#exampleTable"+(cid==mtable?"":"_"+cid)).find(".selected").find('input[type=hidden]').first().val()){
+ if(cid==mtable){
+ $("#main_tableContent").find(".require-select").hide();
+ $("#main_tableContent").find("ul").first().find("a").first().click();
+ if($(".breadcrumb").children().length==4)
+ $(".breadcrumb").children().last().remove();
+
+ }else{
+ $("#sub_tableContent_"+cid).find(".require-select").hide();
+ $("#sub_tableContent_"+cid).find("ul").first().find("a").first().click();
+ }
+ return;
+ }
+ var fields=[]
+ var sizedFields=[];
+ var sizedFieldsAlias=[];
+ var notSizedFields=[];
+ for(var i in editSchema[cid]){
+ for(var j in editSchema[cid][i]){
+ //console.log(JSON.stringify(editSchema[cid][i][j]));
+ if(editSchema[cid][i][j]["ftype"]=="5"){
+ sizedFields.push(editSchema[cid][i][j]["name"].replace(/wkb_geometry/g,"geometry"));
+ sizedFieldsAlias.push(editSchema[cid][i][j]["id"]);
+ }
+ else{
+ notSizedFields.push(editSchema[cid][i][j]["name"].replace(/wkb_geometry/g,"geometry")+" AS \""+editSchema[cid][i][j]["id"]+"\"");
+ try{
+ var tmp=JSON.parse(editSchema[cid][i][j]["dependencies"]);
+ var sqlReq="";
+ var sqlClause="";
+ var sqlParams="";
+ var sqlParam=0;
+ var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
+ var hasDep=false;
+ var previousElements=[];
+ for(k in tmp)
+ for(l in tmp[k]){
+ //console.log(JSON.stringify(tmp[k][l]));
+ if(l=="myself"){
+ for(m in tmp[k][l])
+ for(n in tmp[k][l][m]){
+ //console.log(JSON.stringify(tmp[k][l][m][n]));
+ if(sqlReq!=""){
+ sqlReq+=", ";
+ sqlParams+=", ";
+ //sqlClause+=" WHERE "+alphabet[sqlParam-1]+"."+tmp[k][l][m][n]["tfield"]+"="+alphabet[sqlParam]+"."+tmp[k][l][m][n]["tfield"];
+
+ }
+ sqlReq+="("+cleanupTableName(tmp[k][l][m][n]["sql_query"])+") as "+alphabet[sqlParam];
+ sqlParams+=alphabet[sqlParam]+"."+tmp[k][l][m][n]["tfield"];
+ sqlParam+=1;
+ if(tmp[k][l][m][n]["dependents"]){
+ //console.log(JSON.stringify(tmp[k][l][m][n]["dependents"]));
+ for(var o in tmp[k][l][m][n]["dependents"]){
+ //console.log(JSON.stringify(tmp[k][l][m][n]["dependents"][o]));
+ for(var p in tmp[k][l][m][n]["dependents"][o]){
+ console.log(tmp[k][l][m][n]["dependents"][o][p]["sql_query"].replace(/from/,","+tmp[k][l][m][n]["dependents"][o][p]["tfield"]+" from"));
+ sqlReq+=", ("+cleanupTableName(tmp[k][l][m][n]["dependents"][o][p]["sql_query"]).replace(/from/,","+tmp[k][l][m][n]["dependents"][o][p]["tfield"]+" from")+") as b";
+ sqlParams+=", b."+tmp[k][l][m][n]["dependents"][o][p]["tfieldf"];
+ sqlParam+=2;
+ sqlReq+=", ("+cleanupTableName(editSchema[cid][i][j]["value"]).replace(/from/,","+tmp[k][l][m][n]["dependents"][o][p]["tfieldf"]+" from")+") as c";
+
+ sqlClause+=" WHERE c."+tmp[k][l][m][n]["dependents"][o][p]["tfieldf"]+"=b."+tmp[k][l][m][n]["dependents"][o][p]["tfieldf"];
+ sqlClause+=" AND b."+tmp[k][l][m][n]["tfield"]+"=a."+tmp[k][l][m][n]["tfield"];
+ sqlClause+=" AND c.id=(SELECT "+editSchema[cid][i][j]["name"]+" FROM "+cleanupTableName(allTables[cid].name)+" where id="+selectedId+")";
+ hasDep=true;
+ }
+ }
+ }
+ }
+ if(!hasDep){
+ var tmpReq=cleanupTableName(editSchema[cid][i][j]["value"]);
+ for(m in tmp[k][l])
+ for(n in tmp[k][l][m]){
+ tmpReq=tmpReq.replace(/from/,","+tmp[k][l][m][n]["tfield"]+" from");
+ if(sqlClause=="")
+ sqlClause+=" WHERE ";
+ else
+ sqlClause+=" "+tmp[k][l][m][n]["cond_join"]+" ";
+ sqlClause+=alphabet[m]+"."+tmp[k][l][m][n]["tfield"]+"=a1."+tmp[k][l][m][n]["tfield"];
+ sqlClause+="";
+ }
+ sqlClause+=" AND a1.id=(SELECT "+editSchema[cid][i][j]["name"]+" FROM "+cleanupTableName(allTables[cid].name)+" where id="+selectedId+")";
+ //sqlReq=(tmpReq);
+ console.log(tmpReq);
+ sqlReq+=", ("+tmpReq+") as a1";
+ }
+ //console.log(JSON.stringify(tmp[k][l]));
+ console.log("SELECT "+sqlParams+" FROM "+sqlReq+" "+sqlClause);
+ var localQuery="SELECT "+sqlParams+" FROM "+sqlReq+" "+sqlClause;
+ var res0=JSON.parse(window.Android.displayTable(localQuery,[]));
+ console.log(JSON.stringify(res0));
+ for(m in res0)
+ for(n in res0[m]){
+ try{
+ console.log("input[name=field_"+n+"],select[name=field_"+n+"],textarea[name=field_"+n+"]");
+ /**/
+ if($('.mm4me_edition').find("input[name=field_"+n+"],select[name=field_"+n+"],textarea[name=field_"+n+"]").first().length)
+ $('.mm4me_edition').find("input[name=field_"+n+"],select[name=field_"+n+"],textarea[name=field_"+n+"]").first().val(res0[m][n]).change();
+ else{
+ for(m0 in tmp[k][l])
+ for(n0 in tmp[k][l][m0]){
+ /*console.log(n0.indexOf(n)<0);
+ console.log(n);
+ console.log(n0);
+ console.log(res0[m][n]);*/
+ if(n0.indexOf(n)>=0){
+ console.log("input[name=field_"+n0+"],select[name=field_"+n0+"],textarea[name=field_"+n0+"]");
+ if(!$('.mm4me_edition').find("input[name=field_"+n+"],select[name=field_"+n+"],textarea[name=field_"+n+"]").first().length)
+ $('.mm4me_edition').find("input[name=field_"+n0+"],select[name=field_"+n0+"],textarea[name=field_"+n0+"]").first().val(res0[m][n]).change();
+ }
+ }
+ }
+ }catch(e){
+ console.log(e);
+ }
+
+ }
+ //if(tmp[k][l]["dependents"])
+ }else{
+ console.log(JSON.stringify(tmp[k][l]));
+ if(tmp[k][l]["tfield"]=="none"){
+ var isNull=JSON.parse(window.Android.displayTable("SELECT CASE WHEN "+l+" is null THEN 1 ELSE 0 END as p FROM "+cleanupTableName(allTables[cid].name)+" where id="+selectedId,[]));
+ console.log(JSON.stringify(isNull));
+ if(isNull[0]["p"]=="0"){
+ console.log(JSON.stringify(isNull));
+ console.log("input[name=field_"+editSchema[cid][i][j]["id"]+"],select[name=field_"+editSchema[cid][i][j]["id"]+"],textarea[name=field_"+editSchema[cid][i][j]["id"]+"]");
+ console.log(k+"");
+ $('.mm4me_edition').find("input[name=field_"+editSchema[cid][i][j]["id"]+"],select[name=field_"+editSchema[cid][i][j]["id"]+"],textarea[name=field_"+editSchema[cid][i][j]["id"]+"]").first().val(k+"").change();
+ }
+ }
+
+ }
+ }
+
+ //if(sqlReq)
+ }catch(e){
+ console.log(e);
+ }
+ }
+ if(editSchema[cid][i][j]["name"].indexOf("unamed")<0)
+ fields.push(editSchema[cid][i][j]["name"].replace(/wkb_geometry/g,"geometry")+" AS \""+editSchema[cid][i][j]["id"]+"\"");
+ }
+ }
+ var ccol=getPKey(cleanupTableName(allTables[cid].name));
+ /* $("#exampleTable"+(cid==mtable?"":"_"+cid)).find(".selected").find('input[type=hidden]').first().val() */
+ var editValues;
+ if(sizedFields.length>0){
+ for(var i=0;i 1000000 and "+ccol+"="+selectedId,[]));
+ //console.log(JSON.stringify(hasElement[0]));
+ if(hasElement[0]["cnt"]!="0"){
+ var nbIteration=parseInt(hasElement[0]["len"])/1000000;
+ var zfields=[]
+ var len=0;
+ var query="";
+ var len1=parseInt(hasElement[0]["len"]);
+ for(var j=0;j0){
+ $("#field_"+j+"_map").show();
+ $("#field_"+j+"_map").off('click');
+ $("#field_"+j+"_map").on('click',function(){
+ console.log("Display table with a selected feature");
+ console.log($(this).prev().val());
+ showElementOnMap($(this).prev().val());
+ });
+ }
+ if($(".btn_field_"+j+"_lat").length>0){
+ //alert(editValues[i][j]);
+ $(".btn_field_"+j+"_lat").html(editValues[i][j]);
+ $(".btn_field_"+j+"_long").html("");
+ $(".btn_field_"+j+"_source").html("");
+ $("input[name='field_"+j+"']").val("POINT"+editValues[i][j]);
+
+ }
+ }
+ //$(".swagEditor").summernote();
+ }
+ }
+
+ for(var i in editSchema[cid]){
+ for(var j in editSchema[cid][i]){
+ if(editSchema[cid][i][j]["name"].indexOf("unamed")>=0){
+ if(editSchema[cid][i][j]["ftype"]==6){
+ var tmp=editSchema[cid][i][j]["value"].split(';');
+ var list=JSON.parse(window.Android.displayTable("select "+tmp[1]+" from "+cleanupTableName(tmp[2])+" where "+tmp[0]+"=(SELECT id from "+cleanupTableName(tblName)+" WHERE ogc_fid="+selectedId+")",[]));
+ editValues["0"][editSchema[cid][i][j]["id"]]=list;
+ for(var k in list){
+ for(var l in list[k]){
+ $('.mm4me_edition').find("select[name=field_"+editSchema[cid][i][j]["id"]+"]").find('option').each(function(){
+ if($(this).val()==list[k][l])
+ $(this).prop("selected",true);
+ });
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(cid==mtable){
+ if($(".breadcrumb").children().length==4)
+ $(".breadcrumb").children().last().remove();
+ $(".breadcrumb").append(' '+editValues["0"]["local_id"]+' ');
+ }
+ ((cid==mtable)?$(".require-select"):$("#sub_tableContent_"+cid).find(".require-select")).first().show();
+ ((cid==mtable)?$(".require-select"):$("#sub_tableContent_"+cid).find(".require-select")).first().find("a").first().click();
+
+ if(toRunOnLoad[cid])
+ for(var i=0;i=0 order by mm4me_editions.step asc",[]);
+ if(MM4ME_DEBUG)
+ console.log(list);
+ list=JSON.parse(list);
+ if(MM4ME_DEBUG)
+ console.log((!allTables[tblId]));
+ if(!allTables[tblId]){
+ allTables[tblId]={"id":id,"name":name,"title":title};
+ }
+ mtable=tblId;
+
+ $(".mm4me_edition").find("ul").first().html("");
+ $(".mm4me_edition").find(".well").first().html("");
+ var cnt=0;
+ for(var i in list){
+ lastEdition[list[i]["id"]]=list[i];
+ var cid=(i==0?list[i]["id"]+"_0":list[i]["id"]);
+ $(".mm4me_edition").find("ul").first().append(''+list[i]["name"]+' ');
+ printEditionFields(list[i],$("#edition_form_edit"),cid,mainTable[id]);
+ }
+ if(list.length==1)
+ $(".mm4me_edition").find("ul").first().hide();
+
+ var aCnt=0;
+ $('.mm4me_edition').find('ul').first().find('a').each(function () {
+ if(aCnt>0)
+ $(this).parent().addClass('require-select');
+ aCnt+=1;
+ });
+ $(".require-select").hide();
+ $('.mm4me_listing').find('ul').first().find('a').first().click();
+ $('.mm4me_edition').find('ul').find('a').first().click();
+ $('.swagEditor').summernote();
+ $(".mm-act-add").click(function(){
+ runInsertQuery($(this).parent().parent(),mainTable[id],editOnlyTableReact);
+ });
+ $(".mm-act-save").click(function(){
+ runUpdateQuery($(this).parent().parent(),mainTable[id],editOnlyTableReact);
+ });
+ $(".breadcrumb").children().last().remove();
+ $(".breadcrumb").append(' '+window.Android.translate('edit')+' ');
+ $(".breadcrumb").append(' '+tblTitle+' ');
+
+ setTimeout(function() { updateChangingFields(changingFields) }, 1500);
+
+ /*for(var i=0;i';
+ else
+ cStr+=changingField[j][ckey]["values"][cIndex][i][lkey]+'';
+ cnt+=1;
+ }
+ $("select[name=field_"+changingField[j][ckey]["id"]+"]").append(cStr);
+ }
+ if(i==0)
+ $("select[name=field_"+changingField[j][ckey]["id"]+"]").html(''+window.Android.translate('none')+' ');
+ }
+ }
+ };
+ };
+ $("select[name=field_"+key+"]").off('change');
+ $("select[name=field_"+key+"]").change(localFunc(changingFields[i][key]["dep"]));
+ $("select[name=field_"+key+"]").change();
+ }
+ }*/
+ $('.mm4me_listing').show();
+ $('.mm4me_content').hide();
+
+}
+
+/*****************************************************************************
+ * In case no server is configured
+ *****************************************************************************/
+function displayNoListing(){
+ $.ajax({
+ method: "GET",
+ url: 'content/nolisting.html',
+ success: function(data){
+ if(MM4ME_DEBUG)
+ console.log('Display warning message on the UI !');
+ $(".mm4me_content").html(data);
+ $(".mm4me_content").find(".pannel-body").find("p").first().html(window.Android.translate("mm_no_db_found"));
+ },
+ error: function(){
+ window.Android.showToast("error !");
+ }
+ });
+}
+
+
+/*****************************************************************************
+ * Authenticate a user
+ *****************************************************************************/
+function authenticate(url,login,passwd,func,func1){
+ var curl=url+"?service=WPS&request=Execute&version=1.0.0&Identifier=authenticate.clogIn&DataInputs=login="+login+";password="+passwd+"&RawDataOutput=Result";
+ if(MM4ME_DEBUG)
+ console.log(curl);
+ $.ajax({
+ method: "GET",
+ url: curl,
+ success: function(data){
+ if(MM4ME_DEBUG)
+ console.log(data);
+ if(func){
+ console.log("Call func!")
+ func();
+ }
+ },
+ error: function(){
+ if(func1){
+ func1();
+ }
+ else{
+ disconnect(url);
+ if(MM4ME_DEBUG)
+ console.log("unable to login!");
+ var hasBeenShown=false;
+ var xml=arguments[0].responseText;
+ $(xml).find("ows\\:ExceptionText").each(function(){
+ window.Android.showToast($(this).text());
+ hasBeenShown=true;
+ });
+ if(!hasBeenShown){
+ window.Android.showToast(JSON.stringify(arguments));
+ }
+ }
+
+ }
+ });
+}
+
+/*****************************************************************************
+ * Disconnect a user
+ *****************************************************************************/
+function disconnect(url,func,func1){
+ var curl=url+"?service=WPS&request=Execute&version=1.0.0&Identifier=authenticate.clogOut&DataInputs=&RawDataOutput=Result";
+ if(MM4ME_DEBUG)
+ console.log(curl);
+ $.ajax({
+ method: "GET",
+ url: curl,
+ success: function(data){
+ if(MM4ME_DEBUG){
+ console.log(data);
+ console.log("** Your are no more connected!");
+ }
+ if(func){
+ func();
+ }
+ },
+ error: function(){
+ if(MM4ME_DEBUG){
+ console.log(curl);
+ console.log("unable to disconnect!");
+ }
+ if(func1){
+ func1();
+ }
+ }
+ });
+}
+
+var geometries={"line":{"geom":null,"constructor": "ol.geom.Linestring"},"polygon":{"geom":null,"constructor":"ol.geom.Polygon","cline":null}};
+var stopTracking=false;
+var currentGeometry="line";
+var currentGeometryField="none";
+var map=null;
+var vectorLayer,vectorLayer1;
+var position;
+
+/*****************************************************************************
+ * Track modification of the GPS location
+ *****************************************************************************/
+function trackCurrentGPSPosition(){
+ console.log("## trackCurrentGPSPosition");
+ updateCurrentMapLocation();
+
+ var tmp0=geometries["origin"].getCoordinates();
+ if(geometries[currentGeometry]["geom"]!=null){
+ var tmp1=geometries[currentGeometry]["geom"].getCoordinates();
+ tmp0=tmp1[tmp1.length-1];
+ }
+ tmp=ol.proj.transform([position[bestIndex].lon,position[bestIndex].lat], 'EPSG:4326','EPSG:3857');
+ console.log(JSON.stringify(tmp0));
+ console.log(JSON.stringify(tmp));
+ $("#currentPosition").html("Position: "+position[bestIndex].lon.toFixed(6)+","+position[bestIndex].lat.toFixed(6)+" ");
+ if(tmp0[0]==tmp[0] && tmp0[1]==tmp[1]){
+ console.log(" !!!!!!!! Same position!!!!!!!! ");
+ if(!stopTracking)
+ setTimeout(function() { trackCurrentGPSPosition();}, 1000);
+ return;
+ }
+
+ console.log(JSON.stringify(tmp0));
+ console.log(JSON.stringify(tmp));
+ if(geometries[currentGeometry]["geom"]==null){
+ //geometries[currentGeometry]=new geometries[currentGeometry]["constructor"]([tmp0,tmp]);
+ if(currentGeometry=="line")
+ geometries[currentGeometry]["geom"]=new ol.geom.LineString([tmp0,tmp]);
+ else
+ geometries[currentGeometry]["geom"]=new ol.geom.LineString([tmp0,tmp]);
+ }else{
+ if(currentGeometry=="line"){
+ tmpCoordinates=geometries[currentGeometry]["geom"].getCoordinates();
+ tmpCoordinates.push(tmp);
+ geometries[currentGeometry]["geom"]=new ol.geom.LineString(tmpCoordinates);
+ }
+ else{
+ if(geometries[currentGeometry]["cline"]==null)
+ tmpCoordinates=geometries[currentGeometry]["geom"].getCoordinates();
+ else
+ tmpCoordinates=geometries[currentGeometry]["cline"].getCoordinates();
+ console.log(JSON.stringify(tmpCoordinates));
+ tmpCoordinates.push(tmp);
+ console.log(JSON.stringify(tmpCoordinates));
+ if(tmpCoordinates.length>2){
+ geometries[currentGeometry]["cline"]=new ol.geom.LineString(tmpCoordinates);
+ tmpCoordinates.push(tmpCoordinates[0]);
+ console.log(JSON.stringify(tmpCoordinates));
+ geometries[currentGeometry]["geom"]=new ol.geom.Polygon();
+ console.log(JSON.stringify(tmpCoordinates));
+ geometries[currentGeometry]["geom"].appendLinearRing(new ol.geom.LinearRing(tmpCoordinates));
+ console.log(JSON.stringify(tmpCoordinates));
+ }
+ }
+
+ }
+ console.log(JSON.stringify(tmp0));
+ console.log(JSON.stringify(tmp));
+ try{
+ console.log(JSON.stringify(geometries[currentGeometry]["geom"].getCoordinates()));
+ var feature=new ol.Feature({geometry: geometries[currentGeometry]["geom"],"name":"myFeature"});
+ vectorLayer1.getSource().clear();
+ vectorLayer1.getSource().addFeatures([feature]);
+ var wkt=new ol.format.WKT();
+ var tmpGeometry=geometries[currentGeometry]["geom"].clone().transform('EPSG:3857', 'EPSG:4326');
+ console.log(wkt.writeGeometry(tmpGeometry));
+ $("input[name='"+currentGeometryField+"']").val(wkt.writeGeometry(tmpGeometry));
+ }catch(e){
+ console.log(e);
+ }
+ console.log(JSON.stringify(tmp0));
+ console.log(JSON.stringify(tmp));
+ if(!stopTracking)
+ setTimeout(function() { trackCurrentGPSPosition();}, 1000);
+ console.log(JSON.stringify(tmp0));
+ console.log(JSON.stringify(tmp));
+}
+
+var modalCallback=null;
+
+function trackStepCurrentGPSPosition(){
+ console.log("## trackStepCurrentGPSPosition");
+ updateCurrentMapLocation();
+ $("#currentPosition").html("Position: "+position[bestIndex].lon.toFixed(6)+","+position[bestIndex].lat.toFixed(6)+" ");
+ if(!stopTracking)
+ setTimeout(function() { trackStepCurrentGPSPosition();}, 1000);
+}
+
+function addCurrentLocation(){
+ console.log("addCurrentLocation!!!!");
+ if(geometries["origin"]==null)
+ geometries["origin"]=new ol.geom.Point(ol.proj.transform([position[bestIndex].lon,position[bestIndex].lat], 'EPSG:4326','EPSG:3857'));
+ else{
+ var tmp0=geometries["origin"].getCoordinates();
+ if(geometries[currentGeometry]["geom"]!=null){
+ var tmp1=geometries[currentGeometry]["geom"].getCoordinates();
+ tmp0=tmp1[tmp1.length-1];
+ }
+ tmp=ol.proj.transform([position[bestIndex].lon,position[bestIndex].lat], 'EPSG:4326','EPSG:3857');
+ console.log(JSON.stringify(tmp0));
+ console.log(JSON.stringify(tmp));
+ $("#currentPosition").html("Position: "+position[bestIndex].lon.toFixed(6)+","+position[bestIndex].lat.toFixed(6)+" ");
+ if(geometries[currentGeometry]["geom"]==null){
+ //geometries[currentGeometry]=new geometries[currentGeometry]["constructor"]([tmp0,tmp]);
+ if(currentGeometry=="line")
+ geometries[currentGeometry]["geom"]=new ol.geom.LineString([tmp0,tmp]);
+ else
+ geometries[currentGeometry]["geom"]=new ol.geom.LineString([tmp0,tmp]);
+ }else{
+ if(currentGeometry=="line"){
+ tmpCoordinates=geometries[currentGeometry]["geom"].getCoordinates();
+ tmpCoordinates.push(tmp);
+ geometries[currentGeometry]["geom"]=new ol.geom.LineString(tmpCoordinates);
+ }
+ else{
+ if(geometries[currentGeometry]["cline"]==null)
+ tmpCoordinates=geometries[currentGeometry]["geom"].getCoordinates();
+ else
+ tmpCoordinates=geometries[currentGeometry]["cline"].getCoordinates();
+ console.log(JSON.stringify(tmpCoordinates));
+ tmpCoordinates.push(tmp);
+ console.log(JSON.stringify(tmpCoordinates));
+ if(tmpCoordinates.length>2){
+ geometries[currentGeometry]["cline"]=new ol.geom.LineString(tmpCoordinates);
+ tmpCoordinates.push(tmpCoordinates[0]);
+ console.log(JSON.stringify(tmpCoordinates));
+ geometries[currentGeometry]["geom"]=new ol.geom.Polygon();
+ console.log(JSON.stringify(tmpCoordinates));
+ geometries[currentGeometry]["geom"].appendLinearRing(new ol.geom.LinearRing(tmpCoordinates));
+ console.log(JSON.stringify(tmpCoordinates));
+ }
+ }
+
+ }
+ try{
+ console.log(JSON.stringify(geometries[currentGeometry]["geom"].getCoordinates()));
+ var feature=new ol.Feature({geometry: geometries[currentGeometry]["geom"],"name":"myFeature"});
+ vectorLayer1.getSource().clear();
+ vectorLayer1.getSource().addFeatures([feature]);
+ var wkt=new ol.format.WKT();
+ var tmpGeometry=geometries[currentGeometry]["geom"].clone().transform('EPSG:3857', 'EPSG:4326');
+ console.log(wkt.writeGeometry(tmpGeometry));
+ $("input[name='"+currentGeometryField+"']").val(wkt.writeGeometry(tmpGeometry));
+ }catch(e){
+ console.log(e);
+ }
+
+ }
+}
+
+function trackStepByStepPosition(elem,ltype){
+ modalCallback=function(){
+ //$("#myModal").find(".glyphicon-ok").parent().show();
+ if(myVectorLayer)
+ myVectorLayer.getSource().clear();
+ geometries["origin"]=null;
+ setTimeout(function() { trackStepCurrentGPSPosition();}, 1000);
+ $("#myModal").find("h4").html(' '+window.Android.translate("gps_track"));
+ $("#myModal").find(".modal-footer").html(
+ ' Cancel '+
+ ' Add '+
+ ' Save '
+ );
+ };
+ currentGeometry=ltype;
+ currentGeometryField=elem;
+ geometries[ltype]["geom"]=null;
+ geometries[ltype]["cline"]=null;
+ if(!$("#map").length)
+ $.ajax({
+ method: "GET",
+ url: './map-modal.html',
+ error: function(){
+ },
+ success: function(data){
+ console.log(data);
+ $("body").append(data);
+ $("#map").css("height",($(window).height()-220)+"px");
+ $('#myModal').modal();
+ addOptionalLocalTiles(true);
+ $('#myModal').on('shown.bs.modal', function () {
+ console.log($("#mmm4me_ls").length);
+ initMapToLocation();
+ localTileIndex=map.getLayers().getLength();
+ /*geometries["origin"]=new ol.geom.Point(ol.proj.transform([position[bestIndex].lon,position[bestIndex].lat], 'EPSG:4326','EPSG:3857'));
+ setTimeout(function() { trackCurrentGPSPosition();}, 1000);*/
+ modalCallback();
+ });
+ $('#myModal').on('hide.bs.modal', function () {
+ console.log("HIDE");
+ stopTracking=true;
+ });
+ }
+ });
+ else{
+ stopTracking=false;
+ $('#myModal').modal();
+ vectorLayer1.getSource().clear();
+ updateCurrentMapLocation();
+ geometries["origin"]=null;
+ setTimeout(function() { trackStepCurrentGPSPosition();}, 1000);
+ }
+}
+/*****************************************************************************
+ * Start tracking GPS location
+ *****************************************************************************/
+function trackGPSPosition(elem,ltype){
+ modalCallback=function(){
+ //$("#myModal").find(".glyphicon-ok").parent().show();
+ if(myVectorLayer)
+ myVectorLayer.getSource().clear();
+ geometries["origin"]=new ol.geom.Point(ol.proj.transform([position[bestIndex].lon,position[bestIndex].lat], 'EPSG:4326','EPSG:3857'));
+ setTimeout(function() { trackCurrentGPSPosition();}, 1000);
+ $("#myModal").find("h4").html(' '+window.Android.translate("gps_track"));
+ $("#myModal").find(".modal-footer").html(
+ ' Cancel '+
+ ' Save '
+ );
+ };
+ currentGeometry=ltype;
+ currentGeometryField=elem;
+ geometries[ltype]["geom"]=null;
+ geometries[ltype]["cline"]=null;
+ if(!$("#map").length)
+ $.ajax({
+ method: "GET",
+ url: './map-modal.html',
+ error: function(){
+ },
+ success: function(data){
+ console.log(data);
+ $("body").append(data);
+ $("#map").css("height",($(window).height()-220)+"px");
+ $('#myModal').modal();
+ addOptionalLocalTiles(true);
+ $('#myModal').on('shown.bs.modal', function () {
+ console.log($("#mmm4me_ls").length);
+ initMapToLocation();
+ localTileIndex=map.getLayers().getLength();
+ /*geometries["origin"]=new ol.geom.Point(ol.proj.transform([position[bestIndex].lon,position[bestIndex].lat], 'EPSG:4326','EPSG:3857'));
+ setTimeout(function() { trackCurrentGPSPosition();}, 1000);*/
+ modalCallback();
+ });
+ $('#myModal').on('hide.bs.modal', function () {
+ console.log("HIDE");
+ stopTracking=true;
+ });
+ }
+ });
+ else{
+ stopTracking=false;
+ $('#myModal').modal();
+ vectorLayer1.getSource().clear();
+ updateCurrentMapLocation();
+ geometries["origin"]=new ol.geom.Point(ol.proj.transform([position[bestIndex].lon,position[bestIndex].lat], 'EPSG:4326','EPSG:3857'));
+ setTimeout(function() { trackCurrentGPSPosition();}, 1000);
+ }
+}
+
+var hasAddedElement=0;
+var myVectorLayer=null;
+function addSelectedElement(wktString){
+ var features=[];
+ try{
+ var format = new ol.format.WKT();
+ features.push(
+ format.readFeature(wktString, {
+ dataProjection: 'EPSG:4326',
+ featureProjection: 'EPSG:3857'
+ })
+ );
+ }catch(e){
+ console.log("Unable to parse WKT ?!"+e)
+ }
+ if(!vectorLayer1){
+ myVectorLayer = new ol.layer.Vector({
+ source: new ol.source.Vector({
+ features: features
+ }),
+ style: new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: "#3333aa",
+ width: 1.4
+ })
+ })
+ });
+ map.addLayer(myVectorLayer);
+ }
+ else{
+ vectorLayer1.getSource().clear();
+ vectorLayer1.getSource().addFeatures(features);
+ }
+ console.log(vectorLayer1.getSource().getExtent());
+ map.updateSize();
+ map.getView().fit(vectorLayer1.getSource().getExtent(),map.getSize());
+ hasAddedElement=1;
+}
+
+/*****************************************************************************
+ * Show selected feature on map
+ *****************************************************************************/
+ var addSelectedIndex=0;
+ var mySelectedElement=null;
+function showElementOnMap(wktString){
+ mySelectedElement=wktString;
+ modalCallback=function(){
+ //$("#myModal").find(".glyphicon-ok").parent().hide();
+ if(addSelectedIndex==0){
+ updateCurrentMapLocation();
+ $("#currentPosition").html("Position: "+position[bestIndex].lon.toFixed(6)+","+position[bestIndex].lat.toFixed(6)+" ");
+ }
+ addSelectedElement(mySelectedElement);
+ $("#myModal").find("h4").html(' '+window.Android.translate("view_feature"));
+ addSelectedIndex++;
+ };
+ //$("#currentPosition").html("Position: "+position[bestIndex].lon.toFixed(6)+","+position[bestIndex].lat.toFixed(6)+" ");
+ if(!$("#map").length)
+ $.ajax({
+ method: "GET",
+ url: './map-modal.html',
+ error: function(){
+ },
+ success: function(data){
+ console.log(data);
+ $("body").append(data);
+ $("#map").css("height",($(window).height()-220)+"px");
+ $('#myModal').modal();
+ addOptionalLocalTiles(true);
+ $('#myModal').on('shown.bs.modal', function () {
+ console.log($("#mmm4me_ls").length);
+ initMapToLocation();
+ localTileIndex=map.getLayers().getLength();
+ modalCallback();
+ });
+ $('#myModal').on('hide.bs.modal', function () {
+ console.log("HIDE");
+ stopTracking=true;
+ });
+ }
+ });
+ else{
+ console.log("OK ");
+ $('#myModal').modal();
+ console.log("OK ");
+ vectorLayer1.getSource().clear();
+ console.log("OK ");
+ updateCurrentMapLocation();
+ console.log("OK ");
+ addSelectedElement(wktString);
+ console.log("OK ");
+ }
+
+ $("#currentPosition").html("Position: "+position[bestIndex].lon.toFixed(6)+","+position[bestIndex].lat.toFixed(6)+" ");
+}
+
+
+/*****************************************************************************
+ * Store the current GPS location in the edit form
+ *****************************************************************************/
+function requireGPSPosition(elem){
+ var position=JSON.parse(window.Android.getGPS());
+ //elem=$("#"+elem);
+ if(position.lat){
+ $(".btn_"+elem+"_lat").html(position.lat);
+ $(".btn_"+elem+"_long").html(position.lon);
+ $(".btn_"+elem+"_source").html(position.source);
+ $("input[name='"+elem+"']").val("POINT("+position.lon+" "+position.lat+")");
+ }else{
+
+ }
+ console.log(JSON.stringify(position));
+}
+
+/*****************************************************************************
+ * Ajax setup to ensure seting "withCredentials" to true
+ *****************************************************************************/
+function ajaxSetup(){
+ $.ajaxSetup({
+ xhrFields: {
+ withCredentials: true
+ }
+ });
+}
+
+/*****************************************************************************
+ * Get the current Network and GPS availability
+ *****************************************************************************/
+function getCurrentStatus(){
+ var tmp=JSON.parse(window.Android.getGNStatus());
+ tmp["gps"]=JSON.parse(tmp["gps"]);
+ updateStatus(tmp['gps'],tmp['net']);
+}
+
+/*****************************************************************************
+ * Display the status icons
+ *****************************************************************************/
+function addStatusControl(){
+ $('.breadcrumb').append(' /'+
+ ''+
+ ''+
+ ''+
+ ' '+
+ ' ');
+}
+
+/*****************************************************************************
+ * Initialize the map and show the current GPS location
+ *****************************************************************************/
+var localTiles,localTiles0;
+var tileLayers=[];
+function initMapToLocation(){
+ if(map)
+ return;
+ var osmSource = new ol.source.OSM();
+
+ var otherLayers=[];
+ var otherLayersSwitcher="";
+ try{
+ var BasesLayersStr=window.Android.getBaseLayers();
+ console.log(BasesLayersStr);
+ var BasesLayers=JSON.parse(BasesLayersStr);
+ for(var i=0;i=4)
+ map.getLayers().item(otherLayers[i]["index"]).setVisible(false);
+ }else{
+ $(this).parent().find("i").removeClass("glyphicon-eye-close").addClass("glyphicon-eye-open");
+ $("#dmopacity_"+i).show();
+ console.log(JSON.stringify(map.getLayers().getLength()));
+ if(!otherLayers[i]["index"]){
+ var myTileLayer=new ol.layer.Tile({source: otherLayers[i]["olLayer"]});
+ var layers = map.getLayers();
+ layers.insertAt(tileLayers.length+1,myTileLayer);
+ otherLayers[i]["index"]=tileLayers.length+1;
+ tileLayers.push(myTileLayer);
+ if(localTileIndex>0)
+ localTileIndex+=1;
+ }
+ else
+ map.getLayers().item(otherLayers[i]["index"]).setVisible(true);
+ }
+ });
+ $(".map").parent().find("input[type=range]").last().on('change',function(){
+ console.log("change to "+$(this).val());
+ map.getLayers().item(otherLayers[i]["index"]).setOpacity($(this).val()/100);
+ });
+
+ })(i);
+ $(".map").parent().find("input[type=checkbox]").parent().off('click');
+ $(".map").parent().find("input[type=checkbox]").parent().on('click',function(){
+ var tmp=$(this).find("input[type=checkbox]");
+ if(tmp.is(":checked")){
+ $(this).find("input[type=checkbox]").prop("checked",false).change();
+ $(this).addClass("select");
+ }
+ else{
+ $(this).find("input[type=checkbox]").prop("checked",true).change();
+ $(this).removeClass("select");
+ }
+ });
+
+ },1);
+ })(i)
+ }
+ }
+ map = new ol.Map({
+ layers: layers,
+ target: 'map',
+ controls: ol.control.defaults({
+ attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
+ collapsible: true
+ })
+ }),
+ view: new ol.View({
+ center: ol.proj.transform([0,0], 'EPSG:4326', 'EPSG:3857'),
+ zoom: 14,
+ maxZoom: 22,
+ minZoom: 1
+ })
+ });
+
+ var bstyle = function (feature, resolution) {
+
+ /*var iconFont = 'glyphicon';
+ var iconFontText = '\e062';*/
+ //var iconFont = 'glyphicon';
+ var iconFont = 'Glyphicons Halflings';
+ var iconFontText = '\ue062';
+ var iconSize = 24;
+ var opacity=0.4;
+ var col = 'rgba(0,255,0,0.6)';
+ if(feature.get("source")=="GPS")
+ col = 'rgba(41,136,54,0.5)';//#298836
+ else if(feature.get("source")=="Network"){
+ col = 'rgba(91,176,75,0.4)';//#5bb04b
+ iconSize = 32;
+ opacity=0.2;
+ }
+ else if(feature.get("source")=="other"){
+ col='rgba(129,208,113,0.5)';//#81d071
+ iconSize = 36;
+ opacity=0.2;
+ }
+ else
+ col='rgba(166,63,39,0.5)'; //#a63f27 //"#EE0000";
+ var styles = [];
+
+ var styleIcon = new ol.style.Style({
+ text: new ol.style.Text({
+ font: 'Normal ' + iconSize + 'px ' + iconFont,
+ text: iconFontText,
+ fill: new ol.style.Fill({ color: col })
+ })
+ });
+ styles.push(styleIcon);
+
+ //console.log(feature.get("type"));
+ return styles;
+ /*return function (feature, resolution) {
+ styles.styleIcon.getText().setText(feature.get("iconCode"));
+ return styles;
+ };*/
+ };
+ position=JSON.parse(window.Android.getFullGPS());
+ //console.log(JSON.stringify(position));
+ if(position.length==0){
+ position=[{lon:3.5,lat:43.5,source:"none"}];
+ }
+ var iconFeatures = [];
+ for(var i=0;i=4)
+ map.getLayers().item(localTileIndex).setVisible(false);
+ }else{
+ $(this).parent().find("i").removeClass("glyphicon-eye-close").addClass("glyphicon-eye-open");
+ $("#dmopacity").show();
+ console.log(JSON.stringify(map.getLayers().getLength()));
+ if(map.getLayers().getLength()0.05){
+ map.getView().setRotation(-direction);
+ oldBearer=direction;
+ }
+ }else{
+ window.Android.stopReportDirection();
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/assets/scripts/gene2.js b/app/src/main/assets/scripts/gene2.js
new file mode 100644
index 0000000..7387afa
--- /dev/null
+++ b/app/src/main/assets/scripts/gene2.js
@@ -0,0 +1,2461 @@
+var MM4ME_DEBUG=true;
+var EDITION_TYPE_FILE=5;
+var mainTable={};
+var mtable=null;
+var refTables={};
+var tblId=null;
+var allTables={};
+var editSchema={};
+var referenceIds={};
+var lastEdition={};
+var tblName=null;
+var toRunOnLoad={};
+var valuesOnLoad=[];
+var definedSqlTypes=[];
+var changingFields=[];
+var lang=window.Android.getLang();
+var langUrl=null;
+if(lang=="fr"){
+ langUrl="file:///android_asset/localisation/French.json";
+}
+
+
+
+
+function loadWelcome3(){
+ window.Android.startWelcomeScreen("draw");
+}
+
+/*****************************************************************************
+ * Update status icon color depending on network and GPS availability
+ *****************************************************************************/
+function updateStatus(gps,internet){
+ if(internet){
+ $('.glyphicon-signal').css('color','#00EE00');
+ }else
+ $('.glyphicon-signal').css('color','#EE0000');
+ $('#gpsMenu1').next().html("");
+ if(gps.length==0){
+ $('#gpsMenu1').css('color','#EE0000');
+ $('#gpsMenu1').next().html(' '+window.Android.translate("no_gps")+' ');
+ }else{
+ $('#gpsMenu1').css('color','#00EE00');
+ for(var i=0;i '+gps[i].source+'');
+ }
+}
+
+/*****************************************************************************
+ * List all available table for a given theme
+ *****************************************************************************/
+function fetchTableForTheme(obj,id){
+ var hasTable=false;
+ var tables=JSON.parse(window.Android.displayTable(
+ "SELECT mm4me_tables.id as tid,mm4me_views.id as id,"+
+ "mm4me_tables.name as name, "+
+ "mm4me_tables.description, "+
+ "mm4me_views.name as title "+
+ " from mm4me_tables,mm4me_views"+
+ " where mm4me_tables.id=mm4me_views.ptid "+
+ "and mm4me_views.visible "+
+ "and mm4me_views.id in (select vid from mm4me_views_themes where tid="+id+")",[]));
+ for(var i=0;i0;
+}
+
+/*****************************************************************************
+ * Create a JSON Object containing the themes hierarchy
+ *****************************************************************************/
+function fetchThemes(obj,id){
+ var cthemes=JSON.parse(window.Android.displayTable("SELECT id,name FROM mm4me_themes where pid = "+id,[]));
+ for(var i=0;i ');
+ $('#tree').treeview({
+ data: allThemes,
+ onNodeSelected: function(event, data) {
+ if(data["myId"]){
+ try{
+ func(data["myId"],data["myName"],data["myTitle"],true);
+ }catch(e){
+ console.log(JSON.stringify(data));
+ console.log(e);
+ window.Android.showToast(e);
+ //exit();
+ }
+ }
+ else{
+ $('#tree').treeview('toggleNodeExpanded',[$("#tree").treeview('getSelected')[0], { silent: true }]);
+ $('#tree').treeview('toggleNodeSelected',[$("#tree").treeview('getSelected')[0], { silent: true }]);
+ //console.log(JSON.stringify(data));
+ //$(this).open();
+ }
+ },
+ showTags: true
+ });
+ var list=JSON.parse(window.Android.displayTable("SELECT mm4me_tables.id as tid,mm4me_views.id as id,mm4me_tables.name as name,mm4me_tables.description,mm4me_views.name as title from mm4me_tables,mm4me_views where mm4me_tables.id=mm4me_views.ptid and mm4me_views.visible",[]));
+ var tableList=list;
+ var total=0;
+ contents=[];
+ for(var i in list){
+ mainTable[list[i]["id"]]=list[i]["tid"];
+ }
+ }
+ catch(e){
+ console.log(e);
+ displayNoListing();
+ }
+}
+
+/*****************************************************************************
+ * Update the breadcrumbs text to translated string
+ *****************************************************************************/
+function updateBreadcrumbs(breadcrumbs){
+ //var breadcrumbs=["home","view"];
+ var lcnt0=0;
+ $('.breadcrumb').find("a").each(function(){
+ $(this).append(window.Android.translate(breadcrumbs[lcnt0]));
+ lcnt0+=1;
+ });
+ $('.breadcrumb').find("li").last().each(function(){
+ $(this).append(window.Android.translate(breadcrumbs[lcnt0]));
+ lcnt0+=1;
+ });
+}
+
+/*****************************************************************************
+ * Convert table names in a string from the PostgreSQL to our SQLite format.
+ * So, convert "AAAXXX.YYYBBB" to "AAAXXX_YYYBBB"
+ *****************************************************************************/
+function cleanupTableName(name){
+ return name.replace(/(\w+)(\d*)\.(\d*)(\w+)/g,"$1$2_$3$4");
+}
+
+/*****************************************************************************
+ * Display an HTML part containing the image produced by Camera or picked from
+ * the photo library.
+ *****************************************************************************/
+function loadNewPicture(cid,id,picture){
+ $(".tab-pane").each(function(){
+ if($(this).is(":visible"))
+ $(this).find("#value_"+id)
+ .html(''+
+ ' '+
+ ' '+
+ '