+ _label: (label_column_name, options) ->\r
+ shorten = options.shorten\r
+ l = if _.isBoolean(shorten)\r
+ if shorten\r
+ # supply default shorten_length\r
+ @constructor.default_label_shorten_length\r
+ else\r
+ # False be no shorten\r
+ null\r
+ else\r
+ # numeric\r
+ shorten\r
+ Pettanr.truncate(@get(label_column_name), l)\r
+ \r
+ label: (options) ->\r
+ ''\r
+ \r
+ get_association: (routes, context, options) ->\r
+ routes = [routes] if _.isString(routes)\r
+ route = routes.shift()\r
+ if _.isEmpty(routes)\r
+ # fetching terminate association. callback\r
+ cxt = options.context || context\r
+ @fetch_association(route, cxt, {\r
+ success: (association_item, options) =>\r
+ options.success.call(context, association_item)\r
+ fail: (response, opt) =>\r
+ options.fail.call(context, response, opt)\r
+ context: context,\r
+ options: options\r
+ })\r
+ else\r
+ # fetching through associations\r
+ @fetch_association(route, this, {\r
+ success: (association_item, options) =>\r
+ association_item.get_association(routes, this, options)\r
+ fail: (response, opt) =>\r
+ options.fail.call(context, response, opt)\r
+ context: context,\r
+ options: options\r
+ })\r
+ \r
+ fetch_association: (name, context, options) =>\r
+ a = @my_class().my_manifest().associations\r
+ fetch_options = {\r
+ success: (association_item) =>\r
+ options.success.call(context, association_item, options.options)\r
+ fail: (response, opt) =>\r
+ options.fail.call(context, response, opt)\r
+ }\r
+ if a.belongs_to[name]\r
+ @get_parent(name, context, fetch_options)\r
+ else if a.has_many[name]\r
+ @get_children(name, context, fetch_options)\r
+ else if a.has_one[name]\r
+ @get_child(name, context, fetch_options)\r
+ else\r
+ console.error('association does not exist in model manifest')\r
+ \r
+ get_parent: (belongs_to_name, context, options = null) ->\r
+ m = Manifest.item_name_to_model(belongs_to_name)\r
+ retriever = new Pettanr.Cache.Retriever(m, @get(belongs_to_name + '_id'))\r
+ return retriever if !options\r
+ @listenTo(retriever, 'retrieve', (item) =>\r
+ options.success.call(context, item)\r
+ )\r
+ @listenTo(retriever, 'fail', (response, opt) =>\r
+ options.fail.call(context, response, opt)\r
+ )\r
+ retriever.retrieve()\r
+ \r
+ get_child: (has_one_name, context, options = null) ->\r
+ list = @has_one(has_one_name)\r
+ list.open(context, {\r
+ success: (items) =>\r
+ callback = options.success\r
+ item = items[0]\r
+ callback.call(context, item)\r
+ fail: (response, opt) =>\r
+ options.fail.call(context, response, opt)\r
+ })\r
+ \r
+ get_children: (has_many_name, context, options = null) ->\r
+ list = @has_many(has_many_name)\r
+ list.open(context, {\r
+ success: (items) =>\r
+ callback = options.success\r
+ callback.call(context, items)\r
+ fail: (response, opt) =>\r
+ options.fail.call(context, response, opt)\r
+ })\r
+ \r
+ has_many: (has_many_name) ->\r
+ has_many_manifest = @my_class().my_manifest().associations.has_many[has_many_name]\r
+ action_name = has_many_manifest.list_action_name\r
+ Locmare.ListGroup.list(\r
+ has_many_name, action_name, {id: @get('id')}\r
+ )\r
+ \r
+ has_one: (has_one_name) ->\r
+ has_one_manifest = @my_class().my_manifest().associations.has_one[has_one_name]\r
+ controller_name = has_one_manifest.model().table_name()\r
+ action_name = has_one_manifest.list_action_name\r
+ Locmare.ListGroup.list(\r
+ controller_name, action_name, {id: @get('id')}\r
+ )\r
+ \r
+ trace_to: (trace_name, context, options) ->\r
+ routes = @my_class().trace_routes()[trace_name]\r
+ if !routes\r
+ console.error('no trace route')\r
+ return\r
+ @get_association(routes, this, {\r
+ success: (association) => \r
+ options.success.call(context, association)\r
+ fail: (response, opt) =>\r
+ options.fail.call(context, response, opt)\r
+ })\r
+ \r