src/cm/media/js/client/c_server_exchange.js
author Production Moz <dev@sopinspace.com>
Sat, 19 May 2012 10:21:54 +0200
changeset 438 fcc5e2f0befd
parent 341 053551f213fb
permissions -rw-r--r--
Fix side effects with csrf token, add csrf_token to every post form + add ajax (see http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request), remove django.middleware.csrf.CsrfViewMiddleware ?!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
//frames['text_view_comment_frames'].gtest.myFunc()
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
var gtest = {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
     3
  renaud : 'RENAUD',
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
     4
  random : Math.random(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
     5
  bernard : 'BERNARD',
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
     6
  myFunc : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
     7
    doExchange("theServerFun", {}, null, this.myRetFunc, this, ['foo', 'bar'])
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
     8
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
     9
  myRetFunc : function(args) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    10
    CY.log('this.renaud : ' + this.renaud) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    11
    CY.log('this.random : ' + this.random) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    12
    CY.log('arg.returned : ' + args.returned) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    13
    CY.log(args.returned) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    14
    CY.log('arg.success : ' + args.success) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    15
    CY.log(args.success) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    16
    //CY.log('arg.success : ' + arg.success) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    17
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    18
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    19
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    20
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    21
// clientArgs should be an array
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    22
doExchange = function(serverFun, obj, formId, retFunc, clientContext, clientArgs, inCaseErrorMsg) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    23
  obj['fun'] = serverFun ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    24
  obj['key'] = sv_key ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    25
  obj['version_key'] = sv_version_key ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    26
//  obj['adminKey'] = sv_adminKey ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    27
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    28
  var cfg = {
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    29
    method: "POST", 
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    30
    data: urlEncode(obj), 
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    31
//    headers: { 'X-Transaction': 'POST Example'},
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    32
    on: {
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    33
//      start: gtH.start,
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    34
//      complete: gtH.complete,
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    35
      success: function(id, oResponse, args){ // args will be {success:clientArgs etc ...
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    36
        var ret = {};
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    37
        if (oResponse.responseText) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    38
          ret = CY.JSON.parse(oResponse.responseText);
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    39
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    40
        if (gLayout.isInFrame() && ('msg' in ret))
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    41
          parent.f_enqueueMsg(ret['msg']) ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    42
          
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    43
        args['returned'] = ret ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    44
        args['successfull'] = true ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    45
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    46
        retFunc.call(clientContext, args);
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    47
      },
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    48
      failure: function(id, oResponse, args){ // args will be {success:clientArgs etc ...
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    49
        if (gLayout.isInFrame())
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    50
          parent.f_enqueueErrorMsg(gettext('error:') + inCaseErrorMsg) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    51
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    52
        args['successfull'] = false ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    53
        retFunc.call(clientContext, args);
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    54
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    55
    },
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    56
//    context: gtH,
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    57
    arguments: {
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    58
//           start: 'foo',
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    59
//           complete: 'bar',
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    60
           success: clientArgs,
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    61
           failure: clientArgs
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    62
           }
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    63
  } ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    64
  if (formId != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    65
    cfg['form'] = {'id':formId};
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    66
  CY.io(sv_client_url, cfg);
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    67
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    68
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    69
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    70
// TODO try to get a stack trace instead of passing an obj 
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    71
warn_server = function(obj) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    72
  obj['fun'] = "warn" ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    73
  obj['key'] = sv_key ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    74
  obj['version_key'] = sv_version_key ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    75
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    76
  var obj2 = CY.UA ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    77
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    78
  var cfg = {
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    79
    method: "POST", 
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    80
    data: urlEncode(CY.merge(obj, obj2))
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    81
  } ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 24
diff changeset
    82
  CY.io('/client/', cfg);
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    83
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    84