source: main/tags/stable4flax/greenstone3/web/interfaces/default/js/format_browse.js@ 28843

Last change on this file since 28843 was 24900, checked in by sjb48, 12 years ago

Format edit tidying - replacing gui_div.js with format 'modules'

File size: 3.8 KB
Line 
1
2console.log("Loading format_browse.js\n");
3
4/* FUNCTIONS FOR FORMAT EDITING */
5
6function getFormatStatement()
7{
8 var formatDiv = document.getElementById('formatStatement');
9 var formatStatement = innerXHTML(formatDiv);
10 return formatStatement;
11}
12
13function checkClassifierRadio()
14{
15 var selection = $('input[name="classifiers"]'); //document.quiz.colour;
16
17 for (i=0; i<selection.length; i++)
18
19 if (selection[i].checked == true)
20 return selection[i].value;
21
22 return "this";
23
24}
25
26function updateFormatStatement()
27{
28 var formatStatement = getFormatStatement();
29
30 var thisOrAll = checkClassifierRadio();
31 console.log(thisOrAll);
32 var myurl = document.URL;
33
34 //var collection_name = getSubstring(myurl, "&c", "&");
35 var service_name = getSubstring(myurl, "&s", "&");
36
37 if(thisOrAll == "all")
38 service_name = "AllClassifierBrowse";
39
40 var classifier_name = null;
41
42 if(service_name == "ClassifierBrowse")
43 classifier_name = getSubstring(myurl, "&cl", "&");
44
45 //var post_url = "http://localhost:8383/greenstone3/dev?a=f&sa=update&c=" + collection_name +"&s=" + service_name;
46 var post_url = host_info.pre_URL + "?a=f&sa=update&c=" + host_info.collection_name +"&s=" + service_name;
47
48 if(classifier_name != null)
49 post_url = post_url + "&cl=" + classifier_name;
50
51 $.post(post_url, {data: formatStatement}, function(data) {
52 //$('.result').innerHTML = data; //html(data);
53
54 // An error is returned because there is no valid XSLT for a format update action, there probably shouldn't be one so we ignore what the post returns.
55 console.log("Successfully updated");
56 //console.log(data);
57 }, 'html');
58}
59
60function saveFormatStatement()
61{
62 var formatStatement = getFormatStatement();
63 var thisOrAll = checkClassifierRadio();
64
65 var myurl = document.URL;
66
67 //var collection_name = getSubstring(myurl, "&c", "&");
68 var service_name = getSubstring(myurl, "&s", "&");
69 var classifier_name = null;
70
71 if(thisOrAll == "all")
72 service_name = "AllClassifierBrowse";
73
74 if(service_name == "ClassifierBrowse")
75 classifier_name = getSubstring(myurl, "&cl", "&");
76
77 //var post_url = "http://localhost:8383/greenstone3/dev?a=f&sa=save&c=" + collection_name +"&s=" + service_name;
78 var post_url = host_info.pre_URL + "?a=f&sa=save&c=" + host_info.collection_name +"&s=" + service_name;
79
80 if(classifier_name != null)
81 post_url = post_url + "&cl=" + classifier_name;
82
83 $.post(post_url, {data: formatStatement}, function(data) {
84 // An error is returned because there is no valid XSLT for a format update action, there probably shouldn't be one so we ignore what the post returns.
85 console.log("Successfully saved");
86 }, 'html');
87}
88
89function find_class(current)
90{
91 var classes = current.className.split(' ');
92 var none = "";
93 for(var i = 0; i < classes.length; i++)
94 {
95 switch(classes[i])
96 {
97 case 'gsf_template':
98 return create_gsf_template(current);
99 default:
100 {
101 console.log("Class not found");
102 return none;
103 }
104 }
105 }
106}
107
108function create_gsf_template(current)
109{
110 // find match text which is an input with class match
111 var match = $(current).find('.match')[0].value;
112 console.log(match);
113
114 // find mode text which is an input with class mode
115 var mode = $(current).find('.mode')[0].value;
116 console.log(mode);
117
118 // "<gsf:template match=\"classifierNode\" mode=\"horizontal\">"
119 var gsf = "<gsf:template match=\"" + match + "\"";
120 if(mode != "vertical")
121 gsf = gsf + " mode=\"" + mode + "\"";
122 gsf = gsf + ">";
123
124 return gsf;
125
126}
127
128
Note: See TracBrowser for help on using the repository browser.