comparison develop/views/Extractapp/taggingtext.php @ 28:e6e9bdc4f256

update the saving response from LGService between different file version
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 03 Mar 2015 18:13:20 +0100
parents 4a29bccb6c59
children fc7342914cdf
comparison
equal deleted inserted replaced
27:4a29bccb6c59 28:e6e9bdc4f256
71 $(form).submit(); 71 $(form).submit();
72 } 72 }
73 // ==== 73 // ====
74 74
75 75
76 handleFileVersionConflict();
77 // Popup to proceeding the saving situations
78 function handleFileVersionConflict() {
79 var info = JSON.parse('<?php echo json_encode($info) ?>');
80 console.log(info['current_fileId']);
81
82 if (info['current_fileId'] != 0){
83 // -- there might be conflicts between different version
84 var retVal = confirm('There were something happened/someone editing in the between of time.\nDo you want to force saving? (There might be conflicts between two versions.)');
85 if( retVal == true ){
86 // TODO: force saving with currentFileId
87 alert("You do the force saving!");
88 //saveTextToLGService();
89
90 }else{
91 var loadLastest = confirm("Do you want to reload for the lastest version? (Your current editing will lost.)");
92 if (loadLastest == true) {
93 // TODO: reload page with the currentFileId
94 alert("You will reload the latest version.");
95
96 var form = document.createElement("form");
97 form.setAttribute("method", "post");
98 form.setAttribute("action", "./TaggingText"); // hand to controller
99 form.setAttribute("target", "_blank");
100
101 var topic_id = JSON.parse('<?php echo json_encode($default_topic_id) ?>');
102
103 var hiddenField = document.createElement("input");
104 hiddenField.setAttribute("name", "topic");
105 hiddenField.setAttribute("value", topic_id);
106 form.appendChild(hiddenField);
107
108 var hiddenField = document.createElement("input");
109 hiddenField.setAttribute("name", "func");
110 hiddenField.setAttribute("value", "Reload"); // reload
111 form.appendChild(hiddenField);
112
113
114
115 _postForContineTagging(form);
116
117 // use the current_fileId to reload the latest version of text
118 console.log('reloaded');
119
120
121 } else {
122 alert("Just a reminder, there is a new version for this branch.");
123 }
124 }
125 }
126 return;
127
128 }
129
76 <?php 130 <?php
77 foreach ( $taglistArray as $taglistValue ) { 131 foreach ( $taglistArray as $taglistValue ) {
78 echo '$(document).on("click", "'.$taglistValue[2].'", function (e) {'."\n"; 132 echo '$(document).on("click", "'.$taglistValue[2].'", function (e) {'."\n";
79 echo "\t".'if ( $(this).prop("tagName").toLowerCase() != "'.$taglistValue[2].'" ) return 0;'."\n"; 133 echo "\t".'if ( $(this).prop("tagName").toLowerCase() != "'.$taglistValue[2].'" ) return 0;'."\n";
80 echo "\t".'if ( $("#editTextId").html() != "Edit the text" ) return 0;'."\n"; 134 echo "\t".'if ( $("#editTextId").html() != "Edit the text" ) return 0;'."\n";
116 el.stop().animate({'top':finaldestination},0); 170 el.stop().animate({'top':finaldestination},0);
117 }); 171 });
118 172
119 173
120 174
121 var info = JSON.parse('<?php echo json_encode($info) ?>'); 175
122 // Popup to proceeding the saving situations 176
123 /* 177 /*
124 if (info['current_fileId']) {
125 var retVal = confirm('There were something happened/someone editing in the between of time.
126 Please choose what you want to proceed the saving.
127 Click "OK" to force saving the current file.');
128 if( retVal == true ){
129 // TODO: force saving
130 alert("You do the force saving!");
131 return true;
132 }else{
133 // TODO: reload with the new file id (current_FileId)
134
135
136 alert("You will reload for the latest version!");
137 return false;
138 }
139
140 };
141
142 */
143
144 178
145 // Popup choosing topic if first time to this section. without branchId 179 // Popup choosing topic if first time to this section. without branchId
146 if (info['file_id'] == 0) { // or info['branchId'] == 0, means new file 180 if (info['file_id'] == 0) { // or info['branchId'] == 0, means new file
147 // ask to choose topic 181 // ask to choose topic
148 $.ajax({ 182 $.ajax({
149 183
150 }); 184 });
151 var popup = document.getElementById('popup-window'); 185 var popup = document.getElementById('popup-window');
152 186
153 // alert('choose topic!'); 187 // alert('choose topic!');
154 }; 188 }
189 */
155 190
156 }); 191 });
157 $(document).on("click", "name", function (e) { 192 $(document).on("click", "name", function (e) {
158 193
159 if ( $("#editTextId").html() != "Edit the text" ) return 0; 194 if ( $("#editTextId").html() != "Edit the text" ) return 0;
357 hiddenField.setAttribute("name", "topic"); 392 hiddenField.setAttribute("name", "topic");
358 hiddenField.setAttribute("value", topic_id); 393 hiddenField.setAttribute("value", topic_id);
359 form.appendChild(hiddenField); 394 form.appendChild(hiddenField);
360 395
361 _postForContineTagging(form); 396 _postForContineTagging(form);
362 397
363 398
364 /* 399 /*
365 var section_id = JSON.parse('<?php echo json_encode($section_id) ?>'); 400 var section_id = JSON.parse('<?php echo json_encode($section_id) ?>');
366 console.log("section_id: "+section_id+", topic_id: "+topic_id); 401 console.log("section_id: "+section_id+", topic_id: "+topic_id);
367 402
420 hiddenField.setAttribute("name", "topic"); 455 hiddenField.setAttribute("name", "topic");
421 hiddenField.setAttribute("value", topic_id); 456 hiddenField.setAttribute("value", topic_id);
422 form.appendChild(hiddenField); 457 form.appendChild(hiddenField);
423 458
424 _postForContineTagging(form); 459 _postForContineTagging(form);
425
426
427 /* 460 /*
428 var section_id = JSON.parse('<?php echo json_encode($section_id) ?>'); 461 var section_id = JSON.parse('<?php echo json_encode($section_id) ?>');
429 console.log("section_id: "+section_id+", topic_id: "+topic_id); 462 console.log("section_id: "+section_id+", topic_id: "+topic_id);
430 463
431 var hiddenField = document.createElement("input"); 464 var hiddenField = document.createElement("input");
565 cnt ++; 598 cnt ++;
566 label = prompt("Please enter your label for this new branch (not empty)", "label for section "+info['section_id']); 599 label = prompt("Please enter your label for this new branch (not empty)", "label for section "+info['section_id']);
567 } 600 }
568 }; 601 };
569 602
603
570 604
571 var form = document.createElement("form"); 605 var form = document.createElement("form");
572 form.setAttribute("method", "post"); 606 form.setAttribute("method", "post");
573 form.setAttribute("action", "./TaggingText"); // hand to controller 607 form.setAttribute("action", "./TaggingText"); // hand to controller
574 form.setAttribute("target", "_self"); 608 form.setAttribute("target", "_self");
590 form.appendChild(hiddenField); 624 form.appendChild(hiddenField);
591 625
592 _postForContineTagging(form); 626 _postForContineTagging(form);
593 627
594 /* 628 /*
629
595 if (info) { 630 if (info) {
596 var hiddenField = document.createElement("input"); 631 var hiddenField = document.createElement("input");
597 hiddenField.setAttribute("name", "fileId"); 632 hiddenField.setAttribute("name", "fileId");
598 hiddenField.setAttribute("value", info['file_id']); 633 hiddenField.setAttribute("value", info['file_id']);
599 form.appendChild(hiddenField); 634 form.appendChild(hiddenField);
683 hiddenField.setAttribute("name", "func"); 718 hiddenField.setAttribute("name", "func");
684 hiddenField.setAttribute("value", "ContinueTagging"); 719 hiddenField.setAttribute("value", "ContinueTagging");
685 form.appendChild(hiddenField); 720 form.appendChild(hiddenField);
686 721
687 _postForContineTagging(form); 722 _postForContineTagging(form);
688 723
689 }; 724 };
725
690 726
691 //Create and append the options 727 //Create and append the options
692 for (var i = 0; i < t.length; i++) { 728 for (var i = 0; i < t.length; i++) {
693 console.log(t[i]['id']+","+t[i]['name']); 729 console.log(t[i]['id']+","+t[i]['name']);
694 var option = document.createElement("option"); 730 var option = document.createElement("option");
721 757
722 var info = JSON.parse( '<?php echo json_encode($info) ?>'); 758 var info = JSON.parse( '<?php echo json_encode($info) ?>');
723 759
724 if (info) { 760 if (info) {
725 // TODO: different field info array based on fileId(branchId) existing or not 761 // TODO: different field info array based on fileId(branchId) existing or not
726 var hiddenField = document.createElement("input"); 762 if (info['file_id']) {
727 hiddenField.setAttribute("name", "fileId"); 763 var hiddenField = document.createElement("input");
728 hiddenField.setAttribute("value", info['file_id']); 764 hiddenField.setAttribute("name", "fileId");
729 form.appendChild(hiddenField); 765 hiddenField.setAttribute("value", info['file_id']);
730 var hiddenField = document.createElement("input"); 766 form.appendChild(hiddenField);
731 hiddenField.setAttribute("name", "branchId"); 767 };
732 hiddenField.setAttribute("value", info['branch_id']); 768 if (info['branch_id']) {
733 form.appendChild(hiddenField); 769 var hiddenField = document.createElement("input");
734 var hiddenField = document.createElement("input"); 770 hiddenField.setAttribute("name", "branchId");
735 hiddenField.setAttribute("name", "userId"); 771 hiddenField.setAttribute("value", info['branch_id']);
736 hiddenField.setAttribute("value", info['user_id']); 772 form.appendChild(hiddenField);
737 form.appendChild(hiddenField); 773 };
738 var hiddenField = document.createElement("input"); 774 if (info['user_id']) {
739 hiddenField.setAttribute("name", "sectionId"); 775 var hiddenField = document.createElement("input");
740 hiddenField.setAttribute("value", info['section_id']); 776 hiddenField.setAttribute("name", "userId");
741 form.appendChild(hiddenField); 777 hiddenField.setAttribute("value", info['user_id']);
742 778 form.appendChild(hiddenField);
743 var hiddenField = document.createElement("input"); 779 };
744 hiddenField.setAttribute("name", "bookId"); 780 if (info['section_id']) {
745 hiddenField.setAttribute("value", info['book_id']); 781 var hiddenField = document.createElement("input");
746 form.appendChild(hiddenField); 782 hiddenField.setAttribute("name", "sectionId");
747 783 hiddenField.setAttribute("value", info['section_id']);
748 var hiddenField = document.createElement("input"); 784 form.appendChild(hiddenField);
749 hiddenField.setAttribute("name", "sectionName"); 785 };
750 hiddenField.setAttribute("value", info['section_name']); 786 if (info['book_id']) {
751 form.appendChild(hiddenField); 787 var hiddenField = document.createElement("input");
752 788 hiddenField.setAttribute("name", "bookId");
753 var hiddenField = document.createElement("input"); 789 hiddenField.setAttribute("value", info['book_id']);
754 hiddenField.setAttribute("name", "bookName"); 790 form.appendChild(hiddenField);
755 hiddenField.setAttribute("value", info['book_name']); 791 };
756 form.appendChild(hiddenField); 792 if (info['section_name']) {
757 } 793 var hiddenField = document.createElement("input");
758 794 hiddenField.setAttribute("name", "sectionName");
795 hiddenField.setAttribute("value", info['section_name']);
796 form.appendChild(hiddenField);
797 };
798 if (info['book_name']) {
799 var hiddenField = document.createElement("input");
800 hiddenField.setAttribute("name", "bookName");
801 hiddenField.setAttribute("value", info['book_name']);
802 form.appendChild(hiddenField);
803 };
804 /*
805 if (info['current_fileId']) {
806 var hiddenField = document.createElement("input");
807 hiddenField.setAttribute("name", "currentFileId");
808 hiddenField.setAttribute("value", info['current_fileId']);
809 form.appendChild(hiddenField);
810 };
811 */
812
813 }
759 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { 814 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
760 document.body.appendChild(form); 815 document.body.appendChild(form);
761 form.submit(); 816 form.submit();
762 } else { 817 } else {
763 form.submit(); // works under IE and Chrome, but not FF 818 form.submit(); // works under IE and Chrome, but not FF
776 hiddenField.setAttribute("name", "topic"); 831 hiddenField.setAttribute("name", "topic");
777 hiddenField.setAttribute("value", topic_id); 832 hiddenField.setAttribute("value", topic_id);
778 form.appendChild(hiddenField); 833 form.appendChild(hiddenField);
779 834
780 _postForContineTagging(form); 835 _postForContineTagging(form);
781 836
837 if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
838 document.body.appendChild(form);
839 form.submit();
840 } else {
841 form.submit(); // works under IE and Chrome, but not FF
842 }
782 } 843 }
783 844
784 845
785 846
786 $(document).on("change", '#smartRegexPopUpSelectWord', function (e) { 847 $(document).on("change", '#smartRegexPopUpSelectWord', function (e) {