2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
21 * Base interface for json based person objects.
26 var JsonActivity = function(opt_params, opt_skipConversions) {
27 opt_params = opt_params || {};
28 if (!opt_skipConversions) {
29 JsonActivity.constructArrayObject(opt_params, "mediaItems", JsonMediaItem);
31 opensocial.Activity.call(this, opt_params);
33 JsonActivity.inherits(opensocial.Activity);
35 JsonActivity.prototype.toJsonObject = function() {
36 var jsonObject = JsonActivity.copyFields(this.fields_);
38 var oldMediaItems = jsonObject['mediaItems'] || [];
39 var newMediaItems = [];
40 for (var i = 0; i < oldMediaItems.length; i++) {
41 newMediaItems[i] = oldMediaItems[i].toJsonObject();
43 jsonObject['mediaItems'] = newMediaItems;
49 // TODO: Split into separate class
50 var JsonMediaItem = function(opt_params) {
51 opensocial.MediaItem.call(this, opt_params['mimeType'],
52 opt_params['url'], opt_params);
54 JsonMediaItem.inherits(opensocial.MediaItem);
56 JsonMediaItem.prototype.toJsonObject = function() {
57 return JsonActivity.copyFields(this.fields_);
61 // TODO: Pull this method into a common class, it is from jsonperson.js
62 JsonActivity.constructArrayObject = function(map, fieldName, className) {
63 var fieldValue = map[fieldName];
65 for (var i = 0; i < fieldValue.length; i++) {
66 fieldValue[i] = new className(fieldValue[i]);
71 // TODO: Pull into common class as well
72 JsonActivity.copyFields = function(oldObject) {
74 for (var field in oldObject) {
75 newObject[field] = oldObject[field];