Project

General

Profile

« Previous | Next » 

Revision 4046

Added by berkley almost 16 years ago

added a tabbed interface

View differences:

util.js
1
var fullDocId;
2

  
3
//log the user in 
1 4
function login()
2 5
{
3 6
  var user = document.getElementById("un").value;
......
27 30
    }, "XML");
28 31
}
29 32

  
33
//update the users status on the page
30 34
function updateStatus()
31 35
{
32 36
  var url = window.location.href;
......
49 53
  
50 54
}
51 55

  
56
//set the header when the user logs in
52 57
function setLoginHeader(loggedin)
53 58
{
54 59
  if(loggedin)
......
60 65
    slideUp("#loginformdiv");
61 66
    $('#maindiv').css("display", "block");
62 67
    $('#bottomimg').css("bottom", "0px");
63
    $.get("metacat", {action:"getlastdocid", scope:"sms"}, 
64
      function(data)
65
      {
66
        var docid = data.substring(data.indexOf("<docid>") + 7, data.indexOf("</docid>"));
67
        var nextid;
68
        if(docid == 'null')
69
        {
70
          nextid = "sms.1.1";
71
        }
72
        else
73
        {
74
          nextid = docid.substring(docid.indexOf(".") + 1, docid.lastIndexOf("."));
75
          nextid++;
76
          nextid = "sms." + nextid + ".1"; 
77
        }
78
        $('#docidtextfield').val(nextid); 
79
      }, 
80
      "XML");
68
    getId();
81 69
  }
82 70
  else
83 71
  {
......
89 77
  }
90 78
}
91 79

  
80
//log the user out.
92 81
function logout()
93 82
{
94 83
  $.get("metacat", {action:"logout", qformat:"xml"});
......
96 85
  setCookie("sms-login", false);
97 86
}
98 87

  
88
//make sure the user is logged in.
99 89
function checkLogin()
100 90
{
101 91
  if(getCookie("sms-login") == "true")
102 92
  {
103 93
    setLoginHeader(true);
104 94
    showDatasets();
95
    showSearchPane();
105 96
  }
106 97
  else
107 98
  {
......
109 100
  }
110 101
}
111 102

  
103
//search the document base in metacat
112 104
function search()
113 105
{
114 106
  var searchval = document.getElementById("searchtextbox").value
......
118 110
  reloadSearchContent(url);
119 111
}
120 112

  
113
//show all of the datasets in metacat
121 114
function showDatasets()
122 115
{
123 116
  var searchval = getCookie('sms-searchval');
......
136 129
  }
137 130
}
138 131

  
132
//reload the search result table
139 133
function reloadSearchContent(url)
140 134
{
141 135
  var page = url.substring(url.indexOf('pagestart=') + 10, url.length);
......
143 137
  $("#searchresulttable").load(url);
144 138
}
145 139

  
140
//upload a file to metacat
146 141
function uploadfile()
147 142
{
148 143
  if(getCookie("sms-login") != "true")
......
150 145
    alert('You cannot upload.  You are not logged in.');
151 146
    return;
152 147
  }
153
  $("form").submit();
148
  if(!checkId(true))
149
  { //make sure the id is valid
150
    alert('The ID prefix you chose is not valid.  The prefix must be a string of alpha characters only.');
151
  }
152
  else
153
  {
154
    if(document.getElementById("datafile").value == null || document.getElementById("datafile").value == "")
155
    {
156
      alert('You must choose a file to upload.');
157
      return;
158
    }
159
    getId(true, true, true);
160
  }
154 161
}
155 162

  
163
//make a document public
156 164
function makepublic(docid)
157 165
{
158 166
  $.get("/sms/metacat?action=setaccess&docid=" + docid + 
......
175 183
        }, "XML");
176 184
}
177 185

  
186
//get the next id and put it in the id text boxes
187
function getId(setFields, setForm, submitForm)
188
{
189
  if(setFields == null)
190
  {
191
    setFields = true;
192
  }
193
  
194
  if(setForm == null)
195
  {
196
    setForm = false;
197
  }
198
  
199
  if(submitForm == null)
200
  {
201
    submitForm = false;
202
  }
203
  
204
  var scopeStr = document.getElementById("docidfamily").value;
205
  //var scopeStr = $('#docidfamily').value;
206
  if(scopeStr == '' || scopeStr == null)
207
  {
208
    scopeStr = "sms";
209
  }
210
  
211
  $.get("metacat", {action:"getlastdocid", scope:scopeStr}, 
212
      function(data)
213
      {
214
        var docid = data.substring(data.indexOf("<docid>") + 7, data.indexOf("</docid>"));
215
        var nextid;
216
        if(docid == 'null')
217
        {
218
          nextid = 1;
219
        }
220
        else
221
        {
222
          nextid = docid.substring(docid.indexOf(".") + 1, docid.lastIndexOf("."));
223
          nextid++;
224
          //nextid = scopeStr + nextid + ".1"; 
225
        }
226
        //$('#docidtextfield').val(nextid);
227
        if(setFields)
228
        {
229
          $('#docidfamily').val(scopeStr);
230
          $('#docidnumber').val(nextid);
231
          $('#docidrevision').val("1");
232
        }
233
        fullDocId = scopeStr + "." + nextid + ".1";
234
        //alert('fullDocId: ' + fullDocId);
235
        if(setForm)
236
        {
237
          //alert('setting docid to ' + fullDocId);
238
          $('#docid').val(fullDocId);
239
        }
240
        
241
        if(submitForm)
242
        {
243
          $("form").submit();
244
        }
245
      }, 
246
      "XML");
247
}
248

  
249
//check for a valid docid
250
function checkId(setForm)
251
{
252
  if(setForm == null)
253
  {
254
    setForm = false;
255
  }
256
  getId(false, setForm, false);
257
  var scopeStr = document.getElementById("docidfamily").value;
258
  var numberStr = document.getElementById("docidnumber").value;
259
  var userDocid = scopeStr + "." + numberStr; 
260
  
261
  //fullDocId is a global var that gets set by getId()
262
  var nextnum = fullDocId.substring(fullDocId.indexOf(".") + 1, fullDocId.lastIndexOf("."));
263
  var regexp = "[^[[a-z]|[A-Z]]+]"; //search for anything thats not an alpha 
264
  var re = new RegExp(regexp);
265
  var match = re.test(scopeStr);
266
  if(match)
267
  { //if it matches, reject
268
    return false;
269
  }
270
  
271
  return true;
272
}
273

  
274
//show the search tab
275
function showSearchPane()
276
{
277
  //hide all, then slide down the search pane
278
  $('#uploaddiv').fadeOut("slow");
279
  $('#searchresultdiv').fadeOut("slow");
280
  $('#searchdiv').fadeIn("slow");
281
  switchTabs('search');
282
}
283

  
284
//show the upload tab
285
function showUploadPane()
286
{
287
  //hide all, then slide down the upload pane
288
  $('#searchdiv').fadeOut("slow");
289
  $('#searchresultdiv').fadeOut("slow");
290
  $('#uploaddiv').fadeIn("slow");
291
  $('#uploadetabimg').hide();
292
  $('#uploadtabimgsel').show();
293
  switchTabs('upload');
294
}
295

  
296
//show the browse tab
297
function showBrowsePane()
298
{
299
  //hide all, then slide down the browse pane
300
  $('#searchdiv').fadeOut("slow");
301
  $('#uploaddiv').fadeOut("slow");
302
  $('#searchresultdiv').fadeIn("slow");
303
  $('#browsetabimg').hide();
304
  $('#browsetabimgsel').show();
305
  switchTabs('browse');
306
}
307

  
308
function switchTabs(tab)
309
{
310
  if(tab == 'browse')
311
  {
312
    $('#searchtabimg').show();
313
    $('#uploadtabimg').show();
314
    $('#browsetabimg').hide();
315
    
316
    $('#uploadtabimgsel').hide();
317
    $('#browsetabimgsel').show();
318
    $('#searchtabimgsel').hide();
319
  }
320
  else if(tab == 'search')
321
  {
322
    $('#searchtabimg').hide();
323
    $('#uploadtabimg').show();
324
    $('#browsetabimg').show();
325
    
326
    $('#uploadtabimgsel').hide();
327
    $('#browsetabimgsel').hide();
328
    $('#searchtabimgsel').show();
329
  }
330
  else if(tab == 'upload')
331
  {
332
    $('#searchtabimg').show();
333
    $('#uploadtabimg').hide();
334
    $('#browsetabimg').show();
335
    
336
    $('#uploadtabimgsel').show();
337
    $('#browsetabimgsel').hide();
338
    $('#searchtabimgsel').hide();
339
  }
340
}
341

  
342
//slide an element up
178 343
function slideUp(id)
179 344
{
180 345
  $(id).slideUp("slow");
181 346
}
182 347

  
348
//slide and element down
183 349
function slideDown(id)
184 350
{
185 351
  $(id).slideDown("slow");
186 352
}
187 353

  
354
//set a cookie
188 355
function setCookie( name, value, expires, path, domain, secure ) 
189 356
{
190 357
  // set time, it's in milliseconds
......
210 377
  ( ( secure ) ? ";secure" : "" );
211 378
}
212 379

  
380
//get a cookie
213 381
function getCookie( check_name ) {
214 382
	// first we'll split this cookie up into name/value pairs
215 383
	// note: document.cookie only returns name=value, not the other components

Also available in: Unified diff